Top 50 Most Commonly Used Linux Commands
In this post, I’ve gathered a list of the top 50 Linux commands. Whether you’re a beginner or a seasoned Linux user, mastering these commands will help you to efficiently manage your Linux-based systems and streamline your workflow. I have categorised commands as per their area of usage.
File and Directory Management:
ls
: Aha!! Curious to know what’s inside directory? 😛
The ls command is one of the most commonly used commands which is used in listing contents inside a directory.
# Show All Files, Includes hidden files (those starting with a dot) in the output.
ls -a
# Provides detailed information about each file or directory, including permissions, number of links, owner, group, size, and timestamp.
ls -l
# Used with -l to display file sizes in a human-readable format (e.g., KB, MB).
ls -lh
# Lists all files and directories recursively.
ls -R
# Sorts files and directories by modification time, with the newest files first.
ls -t
# Sorts files and directories by size, with the largest files first.
ls -S
# Reverses the order of the sort (used with other options like -t or -S).
ls -tr
# Lists one file or directory per line. This is useful for piping the output to other commands.
ls -1
pwd
: Did you lost your way and want to know your current location? 😬
This command will help you find the current working directory path.cd
: Want to move to new location? 📍
Using this command you can navigate through directories efficiently.mkdir
: I see you want your own directory? Why wait create one, Create a new directory.
# Creates a directory named mydir in the current directory.
mkdir mydir
# Creates three directories: dir1, dir2, and dir3.
mkdir dir1 dir2 dir3
# Creates a directory structure parent/child/grandchild
mkdir -p parent/child/grandchild
# Creates a directory named mydir with permissions set to 755
mkdir -m 755 mydir
cp
: Want to replicate the data? Copy files and directories.touch
: Create an empty file/ Change timestamp of the file.
# Create an empty file
touch file.txt
# Updates only the access time of the file.txt
touch -a file.txt
# Sets the timestamp of the file.txt to August 24,2024, 9:30 AM
touch -t 202408240930
mv
: Move or rename files and directories.rm
: Want to get rid of unwanted files and directory?
# Recursively removes directory ad it's contents
rm -r directory/
# Forces removal of file.txt without prompting
rm -r file.txt
# Forcefully and recursively removes directory contents
rm -rf directory/
# Prompts before removing file.txt
rm -i file
find
: Looking for something?grep
: Search for text within files.cat
: Curious about what’s written in file?less
ormore
: View files page by page.
File Permissions:
chmod
: Change file permissions.
# Set permission to file.txt
chmod 755 file.txt
# Applies the permission changes recursively to all files and directories.
chmod -R 755 my_directory/
# Sets the permissions of the target file(s) to match those of the reference file.
chmod --reference=reference_file.txt target_file.txt
chown
: Change file ownership.
System Information:
top
: Display real-time system resource usage.free
: Display system memory usage.df
: Show disk space usage.du
: Display directory space usage.uptime
: Check how long system is up.
Package Management:
apt
oryum
: Package management for Debian/Ubuntu or Red Hat/CentOS systems, respectively.dpkg
(Debian) orrpm
(Red Hat): Install, query, or remove packages.npm
: Node.js package manager.composer
: PHP package manager.
Process Management:
ps
: List running processes.kill
: Terminate processes.pgrep
andpkill
: Find and kill processes by name.systemctl
: Control systemd services.
Networking:
ping
: Test network connectivity.ifconfig
orip
: Network interface configuration.netstat
orss
: Network statistics and connections.curl
andwget
: Download files from the internet.ssh
: Securely connect to remote servers.nc
: Netcat for network troubleshooting.traceroute
ormtr
: Trace network routes.
Text Editing:
nano
orvim
: Text editors for quick edits or advanced editing.sed
: Stream editor for text manipulation.awk
: Text processing and pattern matching.
Compression and Archiving:
tar
: Create and extract tar archives.zip
andunzip
: Compress and decompress files in ZIP format.
Web Server Management:
nginx
orapache2ctl
: Manage Nginx or Apache web servers.systemctl
: Control web server services.
Database Management:
mysql
orpsql
: Command-line clients for MySQL or PostgreSQL.mongod
andmongo
: Start and interact with MongoDB.
Version Control:
git
: Manage version control with Git (Cheatsheet : https://training.github.com/downloads/github-git-cheat-sheet/)
Docker:
docker
: Manage Docker containers. (List of docker commands : https://docs.docker.com/reference/cli/docker/)
docker-compose
: Define and run multi-container Docker applications.
File Transfer:
rsync
: Efficiently transfer and synchronize files between directories or servers.
Options
-a
: Archive mode. It preserves permissions, timestamps, symbolic links, and other attributes. This is equivalent to-rlptgoD
(recursive, links, permissions, timestamps, group, owner, devices).-v
: Verbose. Displays detailed information about the transfer process.-z
: Compress file data during the transfer, which reduces bandwidth usage.-r
: Recursive. Copies directories recursively.-u
: Update. Skips files that are newer on the destination.-e
: Specifies the remote shell to use, such asssh
.--delete
: Deletes files in the destination directory that are not in the source directory.
rsync [options] source destination
# Synchronize a file from one directory to another on the same system.
rsync -av source_file.txt /path/to/destination/
# Synchronize the contents of two directories, including all subdirectories.
rsync -av /source_directory/ /destination_directory/
# Synchronize a directory from a local machine to a remote server.
rsync -avz -e ssh /local_directory/ user@remote_host:/remote_directory/
# Make a mirror of a source directory in the destination, deleting files in the destination that no longer exist in the source.
rsync -av --delete /source_directory/ /destination_directory/
# Synchronize a directory but exclude files matching a pattern.
rsync -av --exclude '*.log' /source_directory/ /destination_directory/
# Perform a dry run to see what changes would be made without actually making any changes.
rsync -av --dry-run /source_directory/ /destination_directory/
# Specify a port for SSH when copying files to a remote server.
rsync -av -e 'ssh -p 2222' /local_directory/ user@remote_host:/remote_directory/
scp
Monitoring:
htop
: Interactive process viewer.tail
: Is used to display the end part of files, Which can be handy for monitoring log files or checking the most recent entries in a file.
# View the Last 10 Lines of a File (Default Behavior)
tail file.txt
# Specifies the number of lines to display from the end of the file
tail -n 20 file.txt
# Continuously monitors the file for new lines as they are added
tail -f /var/log/syslog
journalctl
: Monitor log files and system logs.
Which of these commands do you use the most? Drop a comment and let us know :D
As always, If you like this article make sure to clapp-clapp 👏 and follow me on Medium for more such articles. Suggestions in the comments are always welcome :)
Since content generation is not an easy process, I wouldn’t mind if you supported me by gifting me a Ko-fi to motivate and boost my confidence :)