In this page, you will find Basic Linux Commands. As you all knows, Linux is widely using in many areas now a days. Generally System Administrators and Linux end users will use this commands a lot in their day to day activities.
System Information Commands
| uname -a |
shows Linux system info |
| uname -r |
shows kernel release info |
| cat /etc/redhat-release |
shows installed Redhat version |
| uptime |
displays system running/life time |
| hostname |
shows system host name |
| hostname -i |
shows ip addresses of the host |
| last reboot |
displays system reboot history |
| date |
displays current date and time |
| cal |
displays monthly calendar |
| mount |
shows mounted filesystems |
File Commands
| ls -l |
shows file type and access permission |
| ls -a |
lists also hidden files |
| ls -al |
lists files and directories detailly |
| pwd |
shows present directory |
| mkdir directory |
creates a directory |
| rm testfile |
deletes file testfile |
| rm -r /testfolder |
deletes directory /testfolder and its contents recursively |
| rm -f testfile |
forcefully deletes testfile file without confirmation |
| rm -rf /testfolder |
forcefully deletes directory /testfolder recursively |
| cp testfile1 testfile2 |
copies testfile1 file to testfile2 file |
| cp -r /folder1 /folder2 |
copies /folder1 directıry to /folder2 directory |
| mv testfile1 testfile2 |
renames or moves file testfile1 to file testfile2 |
| touch testfile |
creates an empty file named testfile |
| cat testfile |
used to view file testfile |
| less testfile |
browse through a text file testfile |
| head testfile |
displays first 10 lines of file testfile |
| tail testfile |
displays last 10 lines of file testfile |
| tail -f testfile |
displays last 10 lines of file testfile and follow it as it grows |
| tail -F testfile |
outputs last lines of testfile as it changes |
| file testfile |
gets type of testfile |
| gpg -c testfile |
encrypts file testfile |
| gpg testfile |
decrypts file testfile |
| gpg testfile |
decrypts file testfile |
| gpg testfile |
decrypts file testfile |
| dir |
shows files in the current directory |
| put testfile |
uploads file testfile from local to remote device by using ftp, before to this command need to need ftp session |
| get file |
downloads file testfile from remote to local device |
ls Options
| -a |
shows all (including hidden) |
| -R |
recursive list |
| -r |
reverse order |
| -t |
sort by last modified |
| -S |
sort by file size |
| -l |
long listing format |
| -1 |
one file per line |
| -m |
comma-separated output |
| -q |
quoted output |
Networking Commands
| arp |
displays ARP table of the device |
| arpwatch |
displays Ethernet activity and Ethernet/IP pairings |
| bmon |
displays bandwidth, captures |
| curl |
used for for file transfer |
| dhclient |
used to analyze clients IP address, subnet mask, gateway, dns server |
| dig |
used for simple DNS lookup |
| dstat |
collects and shows system resources |
| ethtool |
used to check settings of your NIC |
| ftp |
used for for file transfer |
| host |
used for IP-Name matching |
| hping3 |
used for packet analyze |
| ifstat |
used to monitor network interface statistics |
| ip addr |
used to check network interfaces and routing activities |
| iptables |
used for ip packet filtering |
| iftop |
displays current bandwidth usage |
| ifup/ifdown |
used to enable or disable interfaces |
| iwconfig |
used to configure wireless interfaces |
| netstat |
to check network connections |
| nload |
used as bandwidth monitoring tool |
| nmap |
used for security audits |
| nslookup |
used also for DNS query |
| ping |
used to check server to server connectivity in network |
| route |
displays IP Routing Table |
| scp |
secured file transfer |
| sftp |
secured file transfer |
| ss |
gives detailed information about the sockets |
| ssh |
used for secure connection |
| tshark |
analyzing and capturing |
| tcpdump |
used for analyzing and capturing |
| telnet |
used for classical unsecured connection |
| ifconfig |
list IP details |
| tracepath |
used for path tracking |
| traceroute |
used for path tracking |
| w |
used to check the current system activity |
| wget |
used to download the content of the web servers |
| whois |
checks the whois database and return with IP and Domain info |
Help Commands
| command -h / command –help |
to review all available options of the “command” |
| info command |
to find info documents about the “command” |
| whatis command |
displays a single line description about the”command” |
| $ man UNIXCOMMAND |
to view detailed man page of the “command” |
| apropos |
used to search man pages for available commands on a specific functionality. |
File Permissions
| chown user |
changes ownership of a file/directory |
| chown user:group filename |
changes user and group for a file or directory |
| File Permissions |
r (read) permission, 4
w (write) permission, 2
x (execute) permission, 1
-= no permission |
| File Owner |
owner/group/everyone |
| File Permissions Examples |
777 | Owner, Group, Everyone has rwx permissions
744 | Owner has rwx permission, Group, Everyone has r permission
755 | Owner has rwx permission, Group, Everyone has rx permissions
776 | Owner, Group has rwx permission, Everyone has rw permissions |
Process Management Commands
| ps |
displays currently running processes |
| ps PID |
gives the status of a particular process |
| pidof |
gives the process ID of a process |
| ps -ef |
displays all running processes on the system |
| ps -ef | grep sshd |
displays process information for sshd |
| top |
displays and manages the top processes |
| htop |
interactive process viewer (top alternative) |
| kill pid |
kills process with process ID of pid |
| pkill sshd |
kills process with name sshd |
| killall sshd |
kills all processes named sshd |
| program & |
starts program in the background |
| bg |
lists and resumes stopped jobs in the background |
| fg |
brings the most recent background job to foreground. |
| fg x |
brings job x to the foreground |
| nice |
starts a process with a given priority |
| renice |
changes priority of an already running process |
| pstree |
displays processes in a tree-like diagram |
| pmap |
displays a memory usage map of processes |
| lsof |
lists files opened by running processes |
User Information Commands
| id |
shows user&group ids of the current user |
| last |
shows the last users logged on |
| whoami |
shows who you are logged in as |
| who |
shows who is logged into the system |
| w |
shows who is logged in and what they do |
| groupadd test |
creates group “test” |
| useradd -c “myid” -m test |
creates “test” account with comment “myid” |
| userdel test |
deletes account “test” |
| usermod -aG sysadmin test |
adds account “test” to the “sysadmin” group |
Search Commands
| grep x file |
searches for x in file |
| grep -i |
case insensitive search |
| grep -r |
recursive search |
| grep -v |
inverted search |
| grep -o |
shows only matched part of the file |
| find /dir/ -name aaa* |
finds files starting with aaa in dir |
| find /dir/ -user test |
finds files owned by test in dir |
| find /dir/ -mmin 10 |
finds files modified less than 10 minutes ago in dir |
| find /home -size +500M |
finds files larger than 500MB in /home |
| find [/folder/location] -name [x] |
finds file names starting with character x |
| whereis aaa |
locates the binary, source, and manual page of aaa |
| locate ssh |
finds the location of ssh quickly |
File Transfer Commands
| scp file.txt server:/tmp |
secure copy file.txt to the /tmp folder on server |
| scp server:/var/www/*.html /tmp |
secure copy *.html files in /var/www/ directory on server to the local /tmp folder |
| scp -r server:/var/www /tmp |
secure copy all files and directories recursively from server to the current system’s /tmp folder. |
| rsync -a /home /backups/ |
synchronize /home to /backups/ |
| rsync -avz /home server:/backups/ |
Synchronize files/directories between the local and remote system with compression enabled |
Disk Usage Commands
| df |
shows free hard disk space on the system |
| df -h |
shows free and used space on mounted filesystems |
| df -i |
shows free and used inodes on mounted filesystems |
| fdisk -l |
List the available physical disk and disk details |
| du -sh |
shows total disk usage off the current directory |
| du -ah |
shows disk usage for all files and directories in readable format |
| free |
shows free RAM on the system |
| free -h |
shows free and used memory |
| findmnt |
shows target mount point for all filesystem |
| mount /dev/disk1 /mountpoint |
mounts a device /dev/disk1 in /mountpoint folder |
Compress and Decompress Commands
| gzip testfile |
compresses testfile file using gzip. |
| bzip2 testfile |
compresses testfile file using bzip2. |
| zip testfile.zip testfile |
compresses testfile file into the archive testfile.zip. |
| tar -czvf archive.tar.gz /home/temp2/ |
compresses a full directory with all sub-directories |
| gzip -d testfile.gz |
extracts testfile.gz with gzip utility |
| gunzip testfile.gz |
extracts testfile.gz with gunzip utility |
| bzip2 -d testfile.bz2 |
extracts testfile.gz with bzip2 utility |
| bunzip2 testfile.bz2 |
extracts testfile.gz with bunzip2 utility |
| unzip testfile.zip |
extracts testfile.zip with zip utility |
| gunzip -c output.txt.gz |
to view the contents of both files without extracting |
| tar cf archive.tar directory |
creates tar named archive.tar containing directory |
| tar xf archive.tar |
extracts the contents from archive.tar |
| tar czf archive.tar.gz directory |
creates a gzip compressed tar file name archive.tar.gz |
| tar xzf archive.tar.gz |
extracts a gzip compressed tar file |
| tar cjf archive.tar.bz2 directory |
creates a tar file with bzip2 compression |
| tar xjf archive.tar.bz2 |
extracts a bzip2 compressed tar file |
Install Commands
| yum search telnet |
Find packages with telnet in name or description |
| yum install telnet |
install telnet package |
| yum info telnet |
displays description and summary info about telnet package |
| rpm -i telnet.rpm |
installs package from local file named telnet.rpm |
| yum remove telnet |
Remove/uninstall telnet package |
| yum list installed |
lists all installed packages with yum |
| yum search [keyword] |
finds a package by a related keyword |
| yum info [package_name] |
shows package information and summary |
| yum install [package_name.rpm] |
installs a package using the YUM package manager |
| dnf install [package_name.rpm] |
installs a package using the DNF package manager |
| apt-get install [package_name] |
installs a package using the APT package manager |
| rpm -i [package_name.rpm] |
installs an .rpm package from a local file |
| rpm -e [package_name.rpm] |
removes an .rpm package |
Hardware Information Commands
| dmesg |
displays messages in kernel ring buffer |
| cat /proc/cpuinfo |
displays CPU information |
| cat /proc/meminfo |
displays memory information |
| lspci -tv |
displays PCI devices |
| lsusb -tv |
displays USB devices |
| dmidecode |
displays DMI/SMBIOS from BIOS |
| hdparm -i /dev/sda |
displays info about disk sda |
| hdparm -tT /dev/sda |
performs a read speed test on disk sda |
| badblocks -s /dev/sda |
tests for unreadable blocks on disk sda |
Related