DEV Community

Cover image for A List of Linux Commands
Zeshan
Zeshan

Posted on

A List of Linux Commands

Here's an easy-to-understand documentation for the listed Linux commands.

Directory Operations

1. ls - List directories

ls
Enter fullscreen mode Exit fullscreen mode

The most frequently used command in Linux to list the contents of a directory.

2. pwd - Print working directory

pwd
Enter fullscreen mode Exit fullscreen mode

Displays the current directory path.

3. cd - Change directory

cd directory-name
Enter fullscreen mode Exit fullscreen mode

Navigates to the specified directory.

4. mkdir - Make directory

mkdir directory-name
Enter fullscreen mode Exit fullscreen mode

Creates a new directory.

5. mv - Move or rename files or directories

mv source destination
Enter fullscreen mode Exit fullscreen mode

Moves or renames files or directories. If moving, it will transfer the file or directory to the new location. If renaming, it will change the name.

6. cp - Copy files or directories

cp -r source destination
Enter fullscreen mode Exit fullscreen mode

Copies files or directories. The -r option allows copying of directories recursively.

7. rm - Remove files or directories

rm file-name
rm -r directory-name
Enter fullscreen mode Exit fullscreen mode

Deletes files or directories. Use the -r option to remove directories recursively.

8. touch - Create empty files

touch file-name
Enter fullscreen mode Exit fullscreen mode

Creates a blank file if it does not already exist.

File Content and Display

9. cat - Concatenate and display file content

cat file-name
Enter fullscreen mode Exit fullscreen mode

Displays the contents of a file.

10. echo - Display message

echo "your message"
Enter fullscreen mode Exit fullscreen mode

Prints the provided message to the terminal.

11. less - View file contents one page at a time

less file-name
Enter fullscreen mode Exit fullscreen mode

Displays file content one page at a time, allowing for navigation.

12. head - Display the first few lines of a file

head -n number-of-lines file-name
Enter fullscreen mode Exit fullscreen mode

Shows the specified number of lines from the top of the file.

13. tail - Display the last few lines of a file

tail -n number-of-lines file-name
Enter fullscreen mode Exit fullscreen mode

Shows the specified number of lines from the bottom of the file.

System and User Information

14. uname - System information

uname -a
Enter fullscreen mode Exit fullscreen mode

Displays basic information about the operating system.

15. whoami - Current username

whoami
Enter fullscreen mode Exit fullscreen mode

Shows the active username.

Search and Compare

16. grep - Search for a string in files

grep "search-string" file-name
Enter fullscreen mode Exit fullscreen mode

Searches for a specified string within a file.

17. diff - Compare files line by line

diff file1 file2
Enter fullscreen mode Exit fullscreen mode

Displays the differences between two files.

18. cmp - Compare two files byte by byte

cmp file1 file2
Enter fullscreen mode Exit fullscreen mode

Checks if two files are identical.

19. comm - Compare two sorted files line by line

comm file1 file2
Enter fullscreen mode Exit fullscreen mode

Combines the functionalities of diff and cmp.

File Compression and Archiving

20. tar - Archive files

tar -cvf archive-name.tar directory-name
tar -xvf archive-name.tar
Enter fullscreen mode Exit fullscreen mode

Creates (-cvf) or extracts (-xvf) tar archives.

21. zip - Compress files

zip archive-name.zip file1 file2
Enter fullscreen mode Exit fullscreen mode

Compresses specified files into a zip archive.

22. unzip - Decompress files

unzip archive-name.zip
Enter fullscreen mode Exit fullscreen mode

Extracts files from a zip archive.

Process and System Management

23. ps - Display active processes

ps aux
Enter fullscreen mode Exit fullscreen mode

Lists all currently running processes.

24. kill and killall - Terminate processes

kill process-id
killall process-name
Enter fullscreen mode Exit fullscreen mode

Terminates processes by their ID or name.

25. df - Disk space usage

df -h
Enter fullscreen mode Exit fullscreen mode

Displays disk space usage in a human-readable format.

Network Commands

26. ifconfig - Network interface configuration

ifconfig
Enter fullscreen mode Exit fullscreen mode

Displays network interfaces and IP addresses.

27. traceroute - Trace network path

traceroute destination-address
Enter fullscreen mode Exit fullscreen mode

Traces all network hops to reach the destination.

28. wget - Download files from the internet

wget url
Enter fullscreen mode Exit fullscreen mode

Downloads files from the specified URL.

Security and Permissions

29. chmod - Change file permissions

chmod permissions file-name
Enter fullscreen mode Exit fullscreen mode

Changes the permissions of a file.

30. chown - Change file owner

chown owner:group file-name
Enter fullscreen mode Exit fullscreen mode

Changes the ownership of a file.

31. sudo - Execute command with superuser privileges

sudo command
Enter fullscreen mode Exit fullscreen mode

Runs the command with elevated (superuser) privileges.

System Utilities

32. clear - Clear terminal screen

clear
Enter fullscreen mode Exit fullscreen mode

Clears the terminal display.

33. man - Manual pages

man command
Enter fullscreen mode Exit fullscreen mode

Accesses the manual pages for the specified command.

34. alias - Create command shortcuts

alias new-command='existing-command'
Enter fullscreen mode Exit fullscreen mode

Creates a custom shortcut for a regularly used command.

35. cal - Display a calendar

cal
Enter fullscreen mode Exit fullscreen mode

Displays a simple calendar in the terminal.

36. top - Display active processes in real-time

top
Enter fullscreen mode Exit fullscreen mode

Shows a real-time view of active processes and their system usage.

User Management

37. useradd and usermod - User management

sudo useradd username
sudo usermod -aG groupname username
Enter fullscreen mode Exit fullscreen mode

Adds a new user or modifies an existing user.

38. passwd - Update user passwords

passwd username
Enter fullscreen mode Exit fullscreen mode

Creates or updates the password for a specified user.

Miscellaneous

39. ln - Create symbolic links

ln -s target link-name
Enter fullscreen mode Exit fullscreen mode

Creates a symbolic link to a target file or directory.

40. dd - Data duplicator for creating bootable USBs

dd if=input-file of=/dev/sdX
Enter fullscreen mode Exit fullscreen mode

Used for low-level copying and conversion of raw data.

41. export - Set environment variables

export VARIABLE_NAME=value
Enter fullscreen mode Exit fullscreen mode

Sets or exports environment variables.

42. whereis - Locate binary, source, and manual pages for a command

whereis command
Enter fullscreen mode Exit fullscreen mode

Finds the location of the binary, source, and manual pages for the specified command.

43. whatis - Display a one-line description of a command

whatis command
Enter fullscreen mode Exit fullscreen mode

Directory and File Operations

44. basename - Extract the base name of a file or directory

basename /path/to/file
Enter fullscreen mode Exit fullscreen mode

Prints the file name without the directory path.

45. dirname - Extract the directory path of a file

dirname /path/to/file
Enter fullscreen mode Exit fullscreen mode

Prints the directory path without the file name.

46. find - Search for files in a directory hierarchy

find /path -name "filename"
Enter fullscreen mode Exit fullscreen mode

Searches for files and directories within a specified path.

File Content and Manipulation

47. awk - Pattern scanning and processing language

awk '{print $1}' file
Enter fullscreen mode Exit fullscreen mode

Processes and analyzes text files, often used for extracting specific fields from text.

48. sed - Stream editor for filtering and transforming text

sed 's/old-text/new-text/' file
Enter fullscreen mode Exit fullscreen mode

Performs basic text transformations on an input stream (file or input from a pipeline).

System and User Information

49. uptime - Show how long the system has been running

uptime
Enter fullscreen mode Exit fullscreen mode

Displays the current time, how long the system has been running, and system load averages.

50. who - Show who is logged on

who
Enter fullscreen mode Exit fullscreen mode

Displays a list of users currently logged into the system.

51. last - Show a listing of last logged-in users

last
Enter fullscreen mode Exit fullscreen mode

Displays a list of users logged in and out since the log file was created.

Network Commands

52. ping - Send ICMP ECHO_REQUEST to network hosts

ping host
Enter fullscreen mode Exit fullscreen mode

Sends packets to a network host to test connectivity.

53. netstat - Network statistics

netstat -tuln
Enter fullscreen mode Exit fullscreen mode

Displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

54. curl - Transfer data from or to a server

curl -O url
Enter fullscreen mode Exit fullscreen mode

Transfers data from or to a server using various protocols (HTTP, FTP, etc.).

System Management

55. htop - Interactive process viewer

htop
Enter fullscreen mode Exit fullscreen mode

Displays an interactive view of system processes and their resource usage.

56. systemctl - Control the systemd system and service manager

systemctl start|stop|restart|status service-name
Enter fullscreen mode Exit fullscreen mode

Manages services and the system state.

Package Management

57. apt - Package management for Debian-based distributions

sudo apt update
sudo apt install package-name
Enter fullscreen mode Exit fullscreen mode

Updates package lists and installs packages on Debian-based systems.

58. yum - Package management for Red Hat-based distributions

sudo yum update
sudo yum install package-name
Enter fullscreen mode Exit fullscreen mode

Updates package lists and installs packages on Red Hat-based systems.

59. pacman - Package management for Arch-based distributions

sudo pacman -Syu
sudo pacman -S package-name
Enter fullscreen mode Exit fullscreen mode

Updates package lists and installs packages on Arch-based systems.

Miscellaneous

60. nc (netcat) - Network troubleshooting and debugging tool

nc -zv host port
Enter fullscreen mode Exit fullscreen mode

Checks the connectivity to a host on a specified port.

61. scp - Secure copy (remote file copy program)

scp source-file user@remote-host:/path/to/destination
Enter fullscreen mode Exit fullscreen mode

Copies files between hosts on a network.

62. rsync - Remote file and directory synchronization

rsync -avz source destination
Enter fullscreen mode Exit fullscreen mode

Synchronizes files and directories between two locations over a network.

63. crontab - Schedule periodic jobs

crontab -e
Enter fullscreen mode Exit fullscreen mode

Edits the crontab file to schedule periodic tasks.

64. at - Schedule commands to run at a specific time

at time
Enter fullscreen mode Exit fullscreen mode

Schedules a command to run at a specified time.

65. hostname - Show or set the system's hostname

hostname
Enter fullscreen mode Exit fullscreen mode

Displays or temporarily sets the system's hostname.

66. df - Disk space usage of file systems

df -h
Enter fullscreen mode Exit fullscreen mode

Shows the disk space usage of file systems in a human-readable format.

67. du - Disk usage of files and directories

du -sh directory-name
Enter fullscreen mode Exit fullscreen mode

Displays the disk usage of a specified directory.

68. history - Show command history

history
Enter fullscreen mode Exit fullscreen mode

Lists the command history for the current session.

69. watch - Execute a program periodically, showing output fullscreen

watch -n interval command
Enter fullscreen mode Exit fullscreen mode

Runs a specified command at regular intervals and displays the output.

70. xargs - Build and execute command lines from standard input

echo 'arguments' | xargs command
Enter fullscreen mode Exit fullscreen mode

These commands further enhance your ability to manage and navigate a Linux system effectively.

Top comments (0)