Little Linux Commands
In this post I shall add little commands that one may forget but could be very useful. My goal is to collect commands for as many distributions are possible. Following distributions are very closely related to each other and, unless otherwise noted, commands specified for one may be run on all of them without modification.
Red Hat: CentOS, Fedora
Ubuntu: Debian
So, for example, if a command is given for Red Hat, it may be run on CentOS and Fedora. If, however, a command is given explicitly for CentOS, it may or may not run on Red Hat and Fedora. If no distribution is given, it is very likely that the command runs on all distributions.
Find Distribution Release Version
If you want to know the release version of a distribution, you may use following commands.
Red Hat, Ubuntu: tail /etc/issue
Red Hat: tail /etc/redhat-releaseSUSE: tail /etc/SuSE-release
Ubuntu (gives more detail): tail /etc/lsb-release
Find Gateway of Network Interface
All:netstat -rn
Runlevel
A runlevel determines what services are started when computer boots up. To find at what runlevel your computer is running at this moment, type the following.
All: runlevel
Output should look something like
N 5
Where N is the previous runlevel and 5 is current runlevel.
Packages Installed
Red Hat: yum list installed
Ubuntu: dpkg -l
Split Files
If you want to split a file into many smaller parts, use this (hat tip: How do I open a 2.5 gig .xml file?):
split -l 50 myfile.txt mynewfile
Show All Users
If you want to list all users of the system, whether they are logged in or not, run the following command. It uses the cut command on the /etc/passwd file.
All: cut -d: -f 1 /etc/passwd
Hat tip for this trick: How to list all your users; man cut.
Lock root
If you want to lock or disable root user, or any other user for that matter, do the following (replace root with the user you want to lock):
All: sudo passwd -l root
Another way to lock a user is to do the following:
All: sudo usermod -L root
Similarly, to unlock a user:
All: sudo usermod -U root
Securely Copy Directory from Remote Server
If you want to use SCP to copy a whole directory from a remote server to your current directory on local machine, do the following:
All: scp -r user@host:/home/me/mydir/. .
The first dot in the path of the remote server tells it to copy all files and folders in the /home/me/ directory, even hidden files and directories. If you use asterisk instead of dot, it will not copy hidden stuff. The second dot means copy everything to the current directory on local machine.
Hat tip for this trick: Moving /home data from old system to new Linux system.
Support for Virtualization in Processor
To see whether your current processor supports Intel-VT (vmx) or AMD-V (svm) virtualization, run the following:
All: egrep -e 'vmx|svm' /proc/cpuinfo
Thanks to CentOS 5 Xen Virtualization.