Programming Languages / Linux commands

Linux system provides Linux commands are run in the terminal used to do all tasks of Administration.Different types of commands are System commands, Hardware commands, Users commands, File Commands, Process Related commands, File Permission commands, Network commands, Compression/Archives commands, Install Packages commands, Install Source (Compilation) commands, Search commands, Login commands, File Transfer commands, Disk Usage commands, Directory Traverse commands.

1. System
S. No Command Details
1 uname DisplaysLinux system information
2 uname -r Displays kernel release information
3 uptime Displays how long the system has been running including load average
4 hostname Shows the system hostname
5 hostname -i Displays the IP address of the system
6 last reboot Shows system reboot history
7 date Displays current system date and time
8 timedatectl Query and change the System clock
9 cal Displays the current calendar month and day
10 w Displays currently logged in users in the system
11 whoami Displays who you are logged in as
12 finger username Displays information about the user

2. Hardware
S. No Command Details
1 dmesg Displays bootup messages
2 cat /proc/cpuinfo Displays more information about CPU e.g model, model name, cores, vendor id
3 cat /proc/meminfo Displays more information about hardware memory e.g. Total and Free memory
4 lshw Displays information about system's hardware configuration
5 lsblk Displays block devices related information
6 free -m Displays free and used memory in the system (-m flag indicates memory in MB)
7 lspci -tv Displays PCI devices in a tree-likediagram
8 lsusb-tv Displays USB devices in a tree-like diagram
9 dmidecode Displays hardware information from the BIOS
10 hdparm-i /dev/xda Displays information about disk data
11 hdparm-tT /dev/xda<:code> Conducts a read speed test on device xda
12 badblocks-s /dev/xda Tests for unreadable blocks on disk

3. Users
S. No Command Details
1 id Displays the details of the active user e.g. uid, gid, and groups
2 last Shows the last logins in the system
3 who Shows who is logged in to the system
4 groupadd "admin" Adds the group 'admin'
5 adduser "Sam" Adds user Sam
6 userdel "Sam" Deletes user Sam
7 usermod Used for changing / modifying user information

4. File Commands
S. No Command Details
1 ls –al Lists files - both regular &hidden files and their permissions as well.
2 pwd Displays the current directory file path
3 mkdir 'directory_name' Creates a new directory
4 rm file_name Removes a file
5 rm -f filename Forcefully removes a file
6 rm -r directory_name Removes a directory recursively
7 rm -rf directory_name Removes a directory forcefully and recursively
8 cp file1 file2 Copies the contents of file1 to file2
9 cp -r dir1 dir2 Recursively Copies dir1 to dir2. dir2 is created if it does not exist
10 mv file1 file2 Renames file1 to file2
11 ln -s /path/to/file_name link_name Creates a symbolic link to file_name
12 touch file_name Creates a new file
13 cat > file_name Places standard input into a file
14 more file_name Outputs the contents of a file
15 head file_name Displays the first 10 lines of a file
16 tail file_name Displays the last 10 lines of a file
17 gpg -c file_name Encrypts a file
18 gpg file_name.gpg Decrypts a file
19 wc Prints the number of bytes, words and lines in a file
20 xargs Executes commands from standard input

5. Process Related
S. No Command Details
1 ps Display currently active processes
2 ps aux | grep 'telnet' Searches for the id of the process 'telnet'
3 pmap Displays memory map of processes
4 top Displays all running processes
5 kill pid Terminates process with a given pid
6 killall proc Kills / Terminates all processes named proc
7 pkill process-name Sendsa signal to a process with its name
8 bg Resumes suspended jobs in the background
9 fg Brings suspended jobs to the foreground
10 fg n job n to the foreground
11 lsof Lists files that are open by processes
12 renice 19 PID makes a process run with very low priority
13 pgrep firefox find Firefox process ID
14 pstree visualizing processes in tree model

6. File Permission
S. No Command Details
1 chmod octal filename Change file permissions of the file to octal
2 Example
3 chmod 777 /data/test.c Set rwx permissions to owner, group and everyone (everyone else who has access to the server)
4 chmod 755 /data/test.c Set rwx to the owner and r_x to group and everyone
5 chmod766 /data/test.c Sets rwx for owner, rw for group and everyone
6 chown owner user-file Change ownership of the file
7 chownowner-user:owner-group file_name Change owner and group owner of the file
8 chown owner-user:owner-group directory Change owner and group owner of the directory

7. Network
S. No Command Details
1 ifconfig Displays IP addresses of all network interfaces
2 netstat -pnltu Displays all active listening ports
3 ping host ping command sends an ICMP echo request to establish a connection to server / PC
4 arp Address Resolution Protocol (arp) used to finding an address of a computer in a network
5 telnet Used to communicate with other computer
6 ftp Used to transfer file. To remote system. ftp 10.2.0.7 Enter : user name,password put a.txt bye
7 Finger Used check the information of any user from remote or local command line interface.
8 ip address add 192.168.0.1/24 dev eth0 Assigns IP address 192.168.0.1 to interface eth0
9 ip addr show Displays IP addresses and all the network interfaces
10 whois domain Retrieves more information about a domain name
11 dig domain Retrieves DNS information about the domain
12 dig -x host Performs reverse lookup on a domain
13 host google.com Performs an IP lookup for the domain name
14 hostname -i Displays local IP address
15 wget file_name Downloads a file from an online source

8. Compression/Archives
S. No Command Details
1 tar -cf home.tar home<:code> Creates archive file called 'home.tar' from file 'home'
2 tar -xf files.tar Extract archive file 'files.tar'
3 tar -zcvf home.tar.gz source-folder Creates gzipped tar archive file from the source folder
4 gzip file Compression a file with .gz extension

9. Install Packages
S. No Command Details
1 rpm -i pkg_name.rpm Install an rpm package
2 rpm -e pkg_name Removes an rpm package
3 dnf install pkg_name Install package using dnf utility

10. Install Source (Compilation)
S. No Command Details
1 ./configure Checks your system for the required software needed to build the program. It will build the Makefile containing the instructions required to effectively build the project
2 make It reads the Makefile to compile the program with the required operations. The process may take some time, depending on your system and the size of the program
3 make install The command installs the binaries in the default/modified paths after the compilation

11. Search
S. No Command Details
1 grep 'pattern' files Search for a given pattern in files
2 grep -r pattern dir Search recursively for a pattern in a given directory
3 locate file Find all instances of the file
4 find /home/ -name "index" Find file names that begin with 'index' in /home folder
5 find /home -size +10000k Find files greater than 10000k in the home folder

12. Login
S. No Command Details
1 sshuser@host Securely connect to host as user
2 ssh -p port_numberuser@host Securely connect to host using a specified port
3 ssh host Securely connect to the system via SSH default port 22
4 telnet host Connect to host via telnet default port 23

13. File Transfer
S. No Command Details
1 scp file1.txt server2/tmp Securely copy file1.txt to server2 in /tmp directory
2 rsync -a /home/apps /backup/ Synchronize contents in /home/apps directory with /backup directory

14. Disk Usage
S. No Command Details
1 df -h Displays free space on mounted systems
2 df -i Displays free inodes on filesystems
3 fdisk -l Shows disk partitions, sizes, and types
4 du -sh Displays disk usage in the current directory in a human-readable format
5 findmnt < Displays target mount point for all filesystems
6 mount device-path mount-point Mount a device

15. Directory Traverse
S. No Command Details
1 cd .. Move up one level in the directory tree structure
2 cd Change directory to $HOME directory
3 cd /test Change directory to /test directory

inode= data structure on a filesystem onLinux( stores = name + actual data).

Home     Back