Little Linux Commands
June 9, 2008
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
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.
Find Gateway of Network Interface
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.
Output should look something like
Where N is the previous runlevel and 5 is current runlevel.
yum list installed
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.
cut -d: -f 1 /etc/passwd
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):
sudo passwd -l root
Another way to lock a user is to do the following:
sudo usermod -L root
Similarly, to unlock a user:
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:
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:
egrep -e 'vmx|svm' /proc/cpuinfo
Thanks to CentOS 5 Xen Virtualization.
What packages are in package group
In Debian, tasksel has various groups of packages, such as Standard, Laptop, etc. But what do these groups contain? Thanks to a post by yankovic_yeah, we know.
aptitude search $(tasksel --task-packages standard)