User Tools

Site Tools


perso:dump:lnx:list_of_useful_commands

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
perso:dump:lnx:list_of_useful_commands [2010/09/29 12:08]
127.0.0.1 (old revision restored)
perso:dump:lnx:list_of_useful_commands [2015/06/18 20:33] (current)
Jean-Christophe Berthon [Deb based package system]
Line 33: Line 33:
 === apt-get commands === === apt-get commands ===
 Here are a dump collection of useful commands with apt/deb system: 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 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 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 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 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 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.+  * ''​%%apt-get install inkscape%%'':​ will install the binary package called inkscape. 
 +  * ''​%%apt-get remove inkscape%%'':​ will uninstall the binary package called inkscape (but possibly not all system configuration files) 
 +  * ''​%%apt-get remove --purge inkscape%%'':​ will uninstall the binary package called inkscape (and purge all possible files installed by the package)
  
 === aptitude commands === === aptitude commands ===
-  * ''​aptitude update'':​ fetch the latest list of applications from the repositories +  * ''​%%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 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 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 install inkscape%%'':​ will install the binary package called inkscape. 
-  * ''​aptitude remove inkscape'':​ will uninstall the binary package called inkscape.+  * ''​%%aptitude remove inkscape%%'':​ will uninstall the binary package called inkscape.
  
 === dpkg commands === === dpkg commands ===
-  * ''​dpkg --get-selections'':​ will list all installed packaged +  * ''​%%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.+  * ''​%%dpkg-reconfigure packagename%%'':​ will reconfigure the package, useful to reconfigure some packages such as apache, mysql, xorg, etc. 
 + 
 +=== Checking which services to restart after update/​upgrade === 
 + 
 +  * ''​%%lsof +L1 -R%%''​ 
 +  * Check in the list of files (rightmost column) that the files are under a system folder such as ''/​usr''​ 
  
 === Synaptic package manager === === Synaptic package manager ===
Line 56: Line 64:
  
 ==== RPM based package system ==== ==== RPM based package system ====
 +
 +There is the generic ''​rpm''​ command.
   * ''​rpm -Uvh package.rpm'':​ install a downloaded RPM package   * ''​rpm -Uvh package.rpm'':​ install a downloaded RPM package
-  ​* ''​yum ​update'': ​+ 
 +Then on Fedora (up to release 21) and CentOS/​RHEL,​ there is ''​yum''​ which allows to manage online repository of rpm packages. 
 +  ​* ''​yum ​upgrade'': ​
   * ''​yum install packages'':​ install package(s) from the repositories   * ''​yum install packages'':​ install package(s) from the repositories
   * ''​yum remove packages'':​ remove an installed package(s)   * ''​yum remove packages'':​ remove an installed package(s)
   * ''​yum list'':​ List packages (installed and available)   * ''​yum list'':​ List packages (installed and available)
 +
 +Not always present/​install are plugins for yum to check which services need to be restarted after an upgrade.
 +  * ''​yum ps''​ based on the yum ps plugin;
 +  * ''​needs-restarting''​ based on ;
 +  * Without using yum, and it works for all Linux systems (whether using RPM or not)
 +    * ''​%%lsof +L1 -R%%''​
 +    * Check in the list of files (rightmost column) that the files are under a system folder such as ''/​usr''​
 +
 +Fedora 22 and newer have replaced ''​yum''​ by ''​dnf''​ and it is possible that future releases of CentOS/RHEL will follow suit.
 +  * ''​dnf upgrade'': ​
 +  * ''​dnf install packages'':​ install package(s) from the repositories
 +  * ''​dnf remove packages'':​ remove an installed package(s)
 +  * ''​dnf list'':​ List packages (installed and available)
  
  
 ===== Services management ===== ===== 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:+**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>​ <​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. 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.
Line 70: Line 95:
 Here are the common parameters for the service (or init.d scripts): start, stop, restart, reload, status 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.+**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]]. 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 ===== ===== Mass storage management =====
Line 82: Line 122:
 <​code>​$ sudo vol_id -u <​device></​code>​ <​code>​$ sudo vol_id -u <​device></​code>​
 One can replace "<​device>"​ by a partition name like /dev/hda1 or /dev/sda5, etc. 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 ====== ====== Networking ======
Line 88: Line 145:
 ==== Usage ==== ==== Usage ====
 Simple usage to log in a remote host: Simple usage to log in a remote host:
-<​code>​ssh [<​username>​@]<​remote host name></​code>​+<​code>​ssh [<​username>​@]<​remote host name></​code>​
 An equivalent (syntax compatible with rlogin): An equivalent (syntax compatible with rlogin):
-<​code>​ssh <remote host name> [-l <​username>​]</​code>​+<​code>​ssh <remote host name> [-l <​username>​]</​code>​
  
 To execute a command without logging in first: To execute a command without logging in first:
-<​code>​ssh [<​username>​@]<​remote host name> <​command></​code>​+<​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: 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.\\+<​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: It is better to use a TTY (basically a pseudo-terminal) like this:
-<​code>​ssh -t [<​username>​@]<​remote host name> sudo <​cmd></​code>​ +<​code>​ssh -t [<​username>​@]<​remote host name> sudo <​cmd></​code>​ 
-in this case, the password is invisible.+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 ==== ==== Tunnelling ====
Line 111: Line 171:
  
 Mounting a shared drive using smbfs (is deprecating...) Mounting a shared drive using smbfs (is deprecating...)
-<​code>​sudo apt-get install smbfs +<​code>​sudo apt-get install smbfs 
-sudo mkdir /​mnt/​share +sudo mkdir /​mnt/​share 
-sudo mount -t smbfs //​win/​Share\ Folder /mnt/share -o username="​win\huygens"</​code>​+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. 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.
  
Line 126: Line 186:
  
 Similar to smbfs: Similar to smbfs:
-<​code>​sudo apt-get install smbfs +<​code>​sudo apt-get install smbfs 
-sudo mkdir /​mnt/​share +sudo mkdir /​mnt/​share 
-sudo mount -t cifs //​host2/​share /mnt/share -o user=huygens,​domain=lan</​code>​+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): In fstab, I have written (added a new line at the end):
Line 136: Line 196:
 <​file>​username=huygens <​file>​username=huygens
 password=huygens</​file>​ 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 ====== ====== Development ======
Line 166: Line 233:
     * -ltpn or -atpn: all (listening) TCP ports with attached process     * -ltpn or -atpn: all (listening) TCP ports with attached process
     * -aupn: all UDP 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.   * **iostat**: get information on CPU and IO usage. Use the flags -xtc for extended disk statistics.
   * **top** (?): instant CPU and process activity   * **top** (?): instant CPU and process activity
   * **perfmeter**:​ displays a small graphic of the CPU 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
 +
 +
 +
 +
 +
 +
 +
  
  
Line 182: Line 262:
   * wireshark   * wireshark
   * mkisofs -JlLrRT -v -V "​Title"​ -P "​Ozner"​ -p "​Jean-Christophe BERTHON"​ -A "​description"​ -hide-joliet-trans-tbl -o image.iso directory/   * 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>​+  * 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   * 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 (openSUSE/​SLES package manager)
 +    * Search for dar: zypper search dar;
 +    * List available patches (smaller updates): zypper list-patches;​
 +    * Info about a patch: zypper info -t patch openSUSE-2015-336;​
 +    * Apply available patches: zypper patch;
 +    * List process(es) that need(s) restart: zypper ps
 +  * iptraf : nice console HMI for monitoring network traffic
 +  * lsof: to verify open files on a filesystem
 +  * lsof +L1 -R: to verify list of open files which have been deleted/​changed (e.g. by an update). The owning processes could need a restart.
 +  * netstat -ltpn
 +  * ethtool eth0 (and ethtool -i eth0; etc.)
 +  * 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.1285754903.txt.gz · Last modified: 2015/05/01 23:32 (external edit)