User Tools

Site Tools


perso:dump:lnx:list_of_useful_commands

This is an old revision of the document!


A PCRE internal error occured. This might be caused by a faulty plugin

====== List of useful commands ====== A repository of useful commands for POSIX systems such as Unix and Linux. ====== Rosetta stone for Unix/Linux ====== Before, we go into more details about specific Linux or Unix commands, there is a really nice web site that tries to gather most common used commands on various Unix and Linux flavour in a table. It is then easy to find equivalences of commands between all those variants. The web site is called the [[http://bhami.com/rosetta.html|Rosetta Stone for Unix]]. ====== General ====== ===== File commands ===== ==== Diff & patch ==== This set of two commands allow to make a difference between two version of a complete file tree and apply it to another tree. This can be really useful let say you are downloading a Blog or Wiki software (version X) and installing it on your personal server. There are a few minor things that annoy you but seems to be OK for a vast majority of person. Therefore, you modify (tune) a few files of the software and use it as is (version Xm). A security update of the software is now available (version Y). If you update to version Y, you loose your change of version Xm. A good solution is to make a difference between version X and Y and apply those same changes to version Xm which become Ym then ;-). The commands are: <code>$ diff -Naur blog-X blog-Y > patch-blog-X-Y $ cd blog-Xm $ patch -Np1 < ../patch-blog-X-Y</code> The gzip version (by replacing gzip by bzip2 and gz by bz2, you could increase the compression ratio): <code>$ diff -Naur blog-X blog-Y | gzip --best > patch-blog-X-Y.gz $ cd blog-Xm $ gzip -cd ../patch-blog-X-Y.gz | patch -Np1</code> The diff can also be done between two revision in CVS: <code>$ cvs rdiff -u -kk -r versionX -r versionY <module-name> > patch-blog-X-Y</code> ====== Administration ====== ===== Package management ===== ==== Deb based package system ==== === System upgrade === * Upgrading to a new stable release<code>$ gksudo "update-manager -c"</code> * Upgrading to the latest development snapshot available<code>$ gksudo "update-manager -c -d"</code> Once your system has been upgraded, you may want to [[:foss:ubuntu:aptclean|clean your list of installed packages]] from obsolete packages or residual data. === apt-get commands === Here are a dump collection of useful commands with apt/deb system: * ''apt-get build-dep inkscape'': will retrieve the development libraries that are required to build [[:foss:wikishelf:inkscape|inkscape]] * ''apt-get update'': fetch the latest list of applications from the repositories * ''apt-get upgrade'': upgrade your applications if some newer release are available in the repositories (once synchronised with apt-get update) * ''apt-get dist-upgrade'': same as before, but smart upgrade are performed (will explained that later, I'm not sure anymore what exactly smart is) * ''apt-get source inkscape'': get the source of inkscape in your current local directory, ready to be compiled and packaged. * ''apt-get install inkscape'': will install the binary package called inkscape. === aptitude commands === * ''aptitude update'': fetch the latest list of applications from the repositories * ''aptitude safe-upgrade'': upgrade your applications if some newer release are available in the repositories (once synchronised with apt-get update) * ''aptitude full-upgrade'': same as before, but smart upgrade are performed (will explained that later, I'm not sure anymore what exactly smart is) * ''aptitude install inkscape'': will install the binary package called inkscape. * ''aptitude remove inkscape'': will uninstall the binary package called inkscape. === dpkg commands === * ''dpkg --get-selections'': will list all installed packaged * ''dpkg-reconfigure packagename'': will reconfigure the package, useful to reconfigure some packages such as apache, mysql, xorg, etc. === Synaptic package manager === Synaptic offers many rich possibilities to manage your applications (both installed or available for installation). You can install, update, search for or remove applications. You can also [[:foss:ubuntu:aptclean|clean your system from obsolete or old packages and even from residual data]]. ==== RPM based package system ==== * ''rpm -Uvh package.rpm'': install a downloaded RPM package * ''yum update'': * ''yum install packages'': install package(s) from the repositories * ''yum remove packages'': remove an installed package(s) * ''yum list'': List packages (installed and available) ===== Services management ===== **Red Hat**-like systems (Red Hat, Fedora, Mandriva, Suse, etc.) offer the 'chkconfig' command to manage services/runlevel. You can configure at which runlevels the service is active or not. For example, activating ssh server only in runlevel 3 and 5 will be done like that: <code>$ sudo chkconfig --level 35 sshd on</code> The activation or not of a service will be taken into account at next restart unless you manually start and stop them using the /etc/init.d scripts or the service command. <code>$ sudo service sshd start</code> Here are the common parameters for the service (or init.d scripts): start, stop, restart, reload, status **Debian**-like systems (incl. Ubuntu) do not provide the chkconfig command. They provide the 'update-rc.d' command that mimic the functionnality of the chkconfig one. They provide also another command, 'invoke-rc.d', that allows to restart, stop and start services. You can find more resources on my [[http://delicious.com/huygens_25/runlevel+management+ubuntu|delicious bookmarks about runlevel and services management for Ubuntu]]. Now there are at least 2 new breads of system init scripts: **systemd** and **upstart**.\\ The former is the easier to use. Everything is cleanly accessible with one command ''systemctl'': <code>$ sudo systemctl disable sshd $ sudo systemctl enable sshd $ sudo systemctl start sshd $ sudo systemctl stop sshd</code> The latter, upstart, is using different commands and requires some manual file editing to do the same thing. The same thing as above can be achieved doing: <code>$ sudo bash -c 'echo "manual" >> /etc/init/sshd.override' $ sudo rm -f /etc/init/sshd.override $ sudo start sshd $ sudo stop sshd</code> I am not going to compare technically the pro's and con's of upstart vs systemd here, but clearly for the user space tools to manipulate both systems, systemd has one entry point and that makes thing simpler IMHO. ===== Mass storage management ===== ==== UUID - device unique identifier ==== In recent Linux distribution, the configuration of device does not rely only on device names. One can now make it rely on "label" or "uuid". A "uuid" is a unique identifier for a device, it can be practical is the device name change often, because its uuid will always be the same. To find out the UUID of a device, use the following command: <code>$ sudo vol_id -u <device></code> One can replace "<device>" by a partition name like /dev/hda1 or /dev/sda5, etc. ===== File permission ===== The set of commands below will create a directory readable by root and users belonging to a group, everyone else can't read it. Only root can write into it. <code># cd /etc # mkdir nginx # chown root:nginx nginx # chmod 2750 nginx # setfacl -d --set u::rwx,g::rx,o::- nginx</code> The two first line are obvious. The third line set the permission as rwx for the user, rx for the group and none for others. In addition the setgid bit (g+s or the '2' in '2750') is used to preserve the group ownership of the parent directory to newly create file under it. The last command (only works if your underlying file system supports ACL) set the default permission of rwx for users, rx for group and none for others. With the above setup creating a file under this directory will result in preserving the ownership and rights of the parent directory: <code># touch nginx/nginx.conf # mkdir nginx/vhosts.d # ls -ld nginx/* -rw-r----- 1 root nginx 0 Feb 28 14:50 nginx/nginx.conf drwxr-s--- 1 root nginx 0 Feb 28 14:50 nginx/vhosts.d</code> ====== Networking ====== ===== SSH & OpenSSH ===== ==== Usage ==== Simple usage to log in a remote host: <code>$ ssh [<username>@]<remote host name></code> An equivalent (syntax compatible with rlogin): <code>$ ssh <remote host name> [-l <username>]</code> To execute a command without logging in first: <code>$ ssh [<username>@]<remote host name> <command></code> However, is the command is a sudo one, the password will be written in clear. It is advise to avoid the form: <code>$ ssh [<username>@]<remote host name> sudo <cmd></code>because it will show the password in clear.\\ It is better to use a TTY (basically a pseudo-terminal) like this: <code>$ ssh -t [<username>@]<remote host name> sudo <cmd></code> or <code>$ ssh -o RequestTTY=yes [<username>@]<remote host name> sudo <cmd></code> in this case, the password is invisible. Example: <code>$ ssh -t 192.168.47.107 sudo shutdown -h now</code> ==== Tunnelling ==== >> [[:foss:wikishelf:ssh:tunnelling|Main article]] Your goal is to access a service on a dedicated host with everything going through SSH. Why? On a remote machine, the only service accessible from the outside World is the SSH service, but you still want to access other services which are behind the firewall of this remote machine. <code>$ ssh -f -C -N -L <local port>:<remote host name>:<remote service port> [-p <ssh port>] [<username>@]<remote host outside name></code> ===== Samba ===== ==== smbfs ==== >> [[:foss:wikishelf:smb:cifs|Guide to Samba manual mount]] Mounting a shared drive using smbfs (is deprecating...) <code>$ sudo apt-get install smbfs $ sudo mkdir /mnt/share $ sudo mount -t smbfs //win/Share\ Folder /mnt/share -o username="win\huygens"</code> It will request you a password. After this the SMB share folder is mapped to the directory /mnt/share. If you go exploring with Nautilus, you go to "File System" -> "mnt" -> "share" and then you can access and open all of your files. To make it automatic, you could add a line in the file that manage partitions and disks (/etc/fstab). <file>//win/Share\040Folder /mnt/share smbfs credentials=/etc/smb-pw/win 0 0</file> A bit of explanation, the spaces in the share drives have to be replace by '\040', and the login and password are going to be place in a file that is private to the super user (not readable by others). Sample content for the credentials file: <file>username=win\huygens password=my_1ncredible_passwd</file> ==== cifs ==== >> [[:foss:wikishelf:smb:cifs|Guide to Samba manual mount]] Similar to smbfs: <code>$ sudo apt-get install smbfs $ sudo mkdir /mnt/share $ sudo mount -t cifs //host2/share /mnt/share -o user=huygens,domain=lan</code> In fstab, I have written (added a new line at the end): <file>//host2/share /mnt/share cifs credentials=/etc/host2-cred,domain=lan 0 0</file> In /etc/host2-cred I have written: <file>username=huygens password=huygens</file> ===== Database ===== ==== MySQL Simple Backup ==== The next instruction works best when using InnoDB engine at least. <code>$ mysqldump -uroot -p --single-transaction --databases <name-db1> <name-db2> | xz > backup.sql.xz</code> ====== Development ====== ===== Version Control System ===== ==== Git VCS ==== [[foss:wikishelf:vcs:git|Main article]] The following list is just a reminder for most used commands. Please see the main article about git for more comprehension. * 'git status' to get the states of which files are staged (will be 'commit'), which files have been modified but not yet staged and which files aren't tracked * 'git add <file|directory>' to add a list of files or directories to the staged status * 'git rm <file|directory>' to remove a list of files or directories from the current local repository, use the option --cached before the list of files/dir if you do not want the files to be removed from the working directory * 'git commit' will commit the list of files and directories currently staged * 'git pull origin' * 'git push origin' * 'git checkout HEAD -- <file>' just in case your deleted <file>, you can restore it with this command ==== Bazaar VCS ==== [[foss:wikishelf:vcs:bazaar|Main article]] ====== Solaris ====== ===== Administration ===== ==== System monitoring ==== * **ipcs**: give all the information on IPC (including shared memory -m, semaphore -s and queues -q) * **netstat**: give all information on current network connections. * -ltpn or -atpn: all (listening) TCP ports with attached process * -aupn: all UDP ports with attached process * -i: prints network statistics for all interfaces * -s: prints detailed network stack stats (e.g. IP, TCP, UDP) * **iostat**: get information on CPU and IO usage. Use the flags -xtc for extended disk statistics. * **top** (?): instant CPU and process activity * **perfmeter**: displays a small graphic of the CPU activity. * **vmstat**: system wide usage (CPU, memory, I/O) * **mpstat -P ALL**: per-processor (core) usage * **slabtop**: Kernel memory usage * **pidstat -d**: disk usage per process ====== Dump (to sort out) ====== * cscope * ctags * silentbob * synergy2 * quicksynergy * mkisofs * cdrecord: sudo cdrecord -v driveropts=burnfree dev=ATA:1,0,0 image.iso ; sudo cdrecord -checkdrive driveropts=help dev=ATA:1,0,0 ; sudo cdrecord -scanbus dev=ATA * tcpdump: 'tcpdump src host <hostname> and dst port <port-number>' ; 'tcpdump -i lo port 80' * wireshark * mkisofs -JlLrRT -v -V "Title" -P "Ozner" -p "Jean-Christophe BERTHON" -A "description" -hide-joliet-trans-tbl -o image.iso directory/ * To use when transforming all WordPress text files from PC to UNIX file format ('\n' instead of '\r\n'), the following command check if the find will be able to select proper file types: <code>$ find . -type f ! -name "*.png" -a ! -name "*.gif" -a ! -name "*.jpg" -a ! -name "*.swf" | awk ' BEGIN { FS = "." } { print $NF }' | sort -u</code> Then, it is possible to use the following command if all file types are for text files: <code>$ find . -type f ! -name "*.png" -a ! -name "*.gif" -a ! -name "*.jpg" -a ! -name "*.swf" | sudo xargs dos2unix -p</code> * Install src.rpm : cd /usr/src/redhat/SRPMS ; sudo rpmbuild --rebuild synergy-1.3.1-1.src.rpm ; sudo rpm -Uvh ../RPMS/x86_64/synergy-1.3.1-1.x86_64.rpm * dmidecode * lsusb, lsmod, lspci * LVM commands: * vgcreate data /dev/sda4 * lvcreate -L200G --name data data * lvcreate -L50G --name vm data * mkfs.ext3 -j -l home /dev/data/data * Backup and restore of partitions * dd if=sda.mbr of=/dev/sda ; dd if=/dev/sda of=sda.mbr bs=512 count=1 * sfdisk /dev/sda < sfdisk.sda ; sfdisk -d /dev/sda > sfdisk.sda * partimage -bd restore /dev/sda1 sda1-boot.000 ; partimage -bd save /dev/sda1 sda1-boot * partimage -bd restore /dev/sda2 sda2-system.000 ; partimage -bd save /dev/sda2 sda2-system * find $HOME/workspace -type f -iname "*.o" -print0 | xargs -0 -P 5 rm -f * zypper search dar * iptraf : nice console HMI for monitoring network traffic * lsof: to verify open files on a filesystem * netstat -ltpn * ethtool eth0 * Command line monitoring tools: * iftop * latencytop * Synology command line for checksums (works with either md5deep, sha1deep or sha256deep): * sha1deep -r -x checksum.sha1 . * sha1deep -r -l dir > dir.sha1

perso/dump/lnx/list_of_useful_commands.1393595467.txt.gz · Last modified: 2015/05/01 23:32 (external edit)