Tutorials - Linux Commands
Useful Linux Commands
Linux Help Commands |
apropos | Apropos keyword - Show all commands with the keyword in their description. The same as the "man -k" command. |
help | Bash shell help for the bash built in command list. The help command gets help for a particular command. |
man | Get help from the manual for a command. |
man -k | keyword - Show all commands with the keyword in their description |
"man 2 kill" | Display page 2 of the kill command |
manpath | Determine user's search path for man pages. |
info | Documentation on Linux commands and programs similar to the man pages but navigation is organized different. |
User and Group Management Commands |
Chown | Change the owner of file(s) to another user. |
Chroot | Run command or interactive shell with special root directory. |
Chsh | Change the login shell. |
Adduser | Ex: adduser mark - Effect: Adds a user to the system named mark |
Passwd | Set a user's pass word. |
Chpasswd | Update password file in batch. |
W | Display users logged in and what they are doing. |
Wall | Send a message to everybody's terminal. |
Who | Display the users logged in. |
whoami | Print effective user id. |
APT Package Tool |
apt-cache search [package] | returns list of packages which corresponds string "searched-packages" |
apt-get install [package] | install / upgrade a deb package |
apt-get update | update the package list |
apt-get upgrade | upgrade all of the installed packages |
apt-get remove [package] | remove a deb package from system |
apt-get check | verify correct resolution of dependencies |
apt-get clean | clean up cache from packages downloaded |
Module and kernel management |
depmod | Handle loadable modules automatically. Creates a makefile-like dependency file. |
dmesg | Print or control the kernel ring buffer. This shows the last kernel startup messages. |
genksyms | Generate symbol version information. |
insmod | Install loadable kernel module. |
lsmod | List currently installed kernel modules. |
modprobe | Used to load a set of modules that are marked with a specified tag. |
rmmod | Unload loadable modules. |
File Management |
ls | Directory listing |
ls -al | Formatted listing with hidden files |
ls -lt | Sorting the Formatted listing by time modification |
cd dir | Change directory to dir |
cd | Change to home directory |
pwd | Show current working directory |
mkdir | dir Creating a directory dir |
cat >file | Places the standard input into the file |
more file | Output the contents of the file |
head file | Output the first 10 lines of the file |
tail file | Output the last 10 lines of the file |
tail -f file | Output the contents of file as it grows, starting with the last 10 lines |
touch file | Create or update file |
rm file | Deleting the file |
rm -r dir | Deleting the directory |
rm -f file | Force to remove the file |
rm -rf dir | Force to remove the directory dir |
cp file1 file2 | Copy the contents of file1 to file2 |
cp -r dir1 dir2 | Copy dir1 to dir2;create dir2 if not present |
mv file1 file2 | Rename or move file1 to file2,if file2 is an existing directory |
ln -s file link | Create symbolic link link to file |
File Permission |
chmod -c –R | chmod file read, write and executable permission |
touch -a –t | modify (or create) file timestamp |
chown -c –R | change file ownership |
chgrp -c –R | change file group permission |
touch -a –t | modify (or create) file timestamp |
File Compression |
bunzip2 file1.bz2 | decompress a file called 'file1.bz2' |
bzip2 file1 | compress a file called 'file1' |
gunzip file1.gz | decompress a file called 'file1.gz' |
rar a file1.rar test_file | create an archive rar called 'file1.rar' |
rar a file1.rar file1 file2 dir1 | compress 'file1', 'file2' and 'dir1' simultaneously |
rar x file1.rar | decompress rar archive |
tar -cvf archive.tar file1 | create a uncompressed tarball |
tar -tf archive.tar | show contents of an archive |
tar -xvf archive.tar | extract a tarball |
tar -xvf archive.tar -C /tmp | extract a tarball into / tmp |
File Search |
find / -name file1 | search file and directory into root filesystem from '/' |
find / -user user1 | search files and directories belonging to 'user1' |
find /home/user1 -name \*.c | search files with '.c' extension within directory '/home/user1' |
find /usr/bin -type f -atime +100 | search binary files are not used in the last 100 days |
find /usr/bin -type f -mtime -10 | search files created or changed within 10 days |
find / -name *.c -exec chmod 755 '{}' \; | search files with '.c' extension and modify permits |
find / -xdev -name \*.c | search files with '.c' extension ignoring removable partitions as cdrom, pen-drive, etc.… |
locate \*.ps | find files with the '.ps' extension - first run 'updatedb' cmd |
whereis halt | show location of a binary file, source or man |
which halt | show full path to a binary / executable |
Directories |
cd /home | enter to directory '/ home' |
cd .. | go back one level |
cd ../.. | go back two levels |
cd | go to home directory |
cd ~user1 | go to home directory |
cd - | go to previous directory |
mkdir dir1 | create a directory called 'dir1' |
mkdir dir1 dir2 | create two directories simultaneously |
mkdir -p /tmp/dir1/dir2 | create a directory tree |
mv dir1 new_dir | rename / move a file or directory |
pwd | show the path of work directory |
rm -f file1 | delete file called 'file1' |
rm -rf dir1 | remove a directory called 'dir1' and contents recursively |
rm -rf dir1 dir2 | remove two directories and their contents recursively |
rmdir dir1 | delete directory called 'dir1' |
Memory Related Commands |
free -m | Display the size of memory in MB |
free -b | display the size of memory in Bytes. |
free -s 5 | Update the command for every 5 sec |
free –V | The -V option, display free command version information. |
Ipcs – m | shared memory on a linux system |
Ipcs – a | Shared memory with all details |
Memstat -p | To identify how much virtual memory is used by the process' associated |
/proc/meminfo | To check memory usage is to read the /proc/meminfo file |
Vmstat - s | Memory usage statistics much like the proc command. |
Disk Related Commands |
Fdisk -l | View all Disk Partitions in Linux (fdisk means fixed disk or format disk) |
Fdisk -l /dev/sda | View Specific partitions |
Fdisk /dev/sda | Check all available fdisk commands |
fdisk –s /dev/sda2 | Check the size of specific partitions |
mkfs.ext4 /dev/sda4 | Format the partitions. |
dpkg-query –W | show the used space by installed deb packages |
du -sh dir1 | estimate space used by directory 'dir1' |
du -sk * | sort -rn | show size of the files and directories sorted by size |
Swamp Memory |
mkswap /dev/hda3 | create a swap filesystem . |
swapon /dev/hda3 | activating a new swap partitions |
swapon /dev/hda2 /dev/hdb3 | activate two swap partitions |
System Information |
arch | Print machine architecture. |
df | Shows disk free space. |
du | Shows disk usage. |
free | Display used and free memory on the system. |
lsdev | Display information about installed hardware via files in the /proc directory. |
lsof | List open files. |
lspci | List PCI devices . |
procinfo | Display system status gathered from proc. |
pstree | Display a tree of processes. |
strace | Trace ssytem calls and signals for a binary program. |
stty | Change and print terminal line settings. |
uname | Print system information, Prints Linux. |
vmstat | Report virtual memory statistics. |
Environment |
env | Show all environment variables. |
export | Set the value of a variable so it is visible to all subprocesses that belong to the current shell. |
printenv | Print all or part of environment. |
reset | Restores runtime parameters for session to default values. |
set | Shows how the environment is set up. This is a builtin bash command. |
Runtime level management |
exit | Terminates the shell. |
halt | Stop the system. |
logout | Log the user off the system. |
poweroff | Brings the system down. |
reboot | Reboot the system. |