Useful Linux Commands 1. System
Useful Linux Commands 1. System
Useful Linux Commands 1. System
1. SYSTEM
# uname –a # Shows linux system information
# uptime # Shows how long system running + load
# hostname # Shows system host name
# last reboot # Shows system reboot history
# date # Shows the current date and time
# cal # Shows this month calendar
# tail -n 10 /var/log/messages # Shows last 10 kernel/syslog messages
# free –m # Shows amount of RAM
2. Hardware
# dmesg # Shows boot messages
# cat /proc/cpuinfo # Shows CPU model
# cat /proc/meminfo # Shows Hardware memory
# lsusb # Shows list of USB devices
3. Users
# id # Show the active user id with login and group
# last # Show last logins on the system
# who # Show ID of users logged on the system
# whoami # Shows your ID
4. File Commands
# cd .. # Goes up one level of the directory tree
# cd ~ or cd # Goes to home directory
# cd /test # Changes to /test directory
# ls –al # Shows all information about files/ directories
# pwd # Shows current directory path
# mkdir directory-name # Creates a directory
# rm file-name # Deletes file(be careful of using rm command)
# rm -r directory-name # Deletes directory recursively (be very careful – can destroy system)
# rm -f file-name # Forcefully removes file
# rm -rf directory-name # Forcefully removes directory recursively
# cp file1 file2 # Copies file1 to file2
# cp -r dir1 dir2 # Copies dir1 to dir2, create dir2 if it doesn’t exist
# mv file1 file2 # Moves files from one place to another
# ln –s /path/to/file-name link-name # Creates symbolic link to file-name
# touch file # Creates or update file (change timestamp)
# cat > file # Places standard input into file
# more file # Shows the contents of file one page at a time
# head file # Shows the first 10 lines of file
# tail file # Shows the last 10 lines of file
5. Process Related
# ps # Shows your currently active processes
# ps aux | grep 'telnet' # Finds all process id related to telnet process
# top # Shows all running processes
# kill pid # Kills process with mentioned pid id
# killall proc # Kilsl all processes named proc
# pkill processname # Sends signal to a process with its name
6. File Permission Related
# chmod id permission file-name # Changes the permissions of file or directory
u = owner, g =group, o = others (not the user or in the group)
+ adds a permission, - remove a permission, = sets to just than permission
a = all, r= read, w=write, x=execute
chmod g+x file.txt # allows members of the group for the file execute it
chmod u=rw, go= file.txt # sets user permission to read and write
# removes all permissions for group and others
7. Network
# ifconfig –a # Shows all network ports and ip address
# ifconfig eth0 # Shows specific ethernet port ip address and details
# ping <IP Address> # Sends echo request to test connection
# wget file # Downloads file from website
# netstat -tupl # Lists all active listening ports(tcp,udp,pid)
9. Uncompress
# tar xf file.tar # Extracts the files from file.tar -a package of files
# tar zxvf file.tar.gz # Extracts the files from file.tar.gz -a compressed tar file
11. Search
# grep pattern files # Searches for pattern in files (you will this command often)
# grep -r pattern dir # Searches recursively for pattern in dir
# find filename # locates file with that name in the path