The command line is one of the most powerful and efficient ways to interact with Linux systems. For developers, knowing the commands can make tasks much faster and easier.
This article provides a reference of useful Linux commands for developers. this commands are organized by category so you can be easily found and used when needed.
Navigation and directory management
ls -> List directory contents
ls -l # long format (permissions, size, date)
ls -la # include hidden files
ls -lh # human-readable sizes
ls -lt # sort by modification time
ls -R # recursive listing
cd -> Change directory
cd /absolute/path
cd .. # go up one level
cd - # switch to previous directory
cd ~ or just cd # go to home directory
pwd -> Print working directory
pwd
mkdir -> Create directories
mkdir <dir_name>
mkdir -p path/to/nested/dir # create parent directories if needed
mkdir -m 755 new_dir # set permissions while creating
File operations
rm -> Remove files/directories
rm file.txt
rm -r directory/ # recursive delete
rm -rf directory/ # force recursive (dangerous!)
rm -i file # interactive confirmation
cp -> Copy files/directories
cp file1 file2
cp -r source/ dest/ # recursive copy
cp -a source/ dest/ # archive mode (preserve attributes)
cp -v file dest/ # verbose output
mv -> Move or rename
mv old_name new_name
mv file /path/to/destination/
mv -i file dest/ # interactive (ask before overwrite)
Viewing searching content
cat -> Display or create files
cat file.txt
cat file1 file2 # concatenate multiple files
cat > newfile.txt # create/overwrite a file
cat >> file.txt # append to a file
cat -n file.txt # show line numbers
grep -> Search text patterns
grep "pattern" file.txt
grep -r "pattern" . # recursive search
grep -i "pattern" file # case-insensitive
grep -n "pattern" file # show line numbers
grep -v "pattern" file # invert match (exclude)
grep -E "regex" file # extended regex
find -> Locate files and directories
find . -name "*.js"
find /path -type f -name "*.log" # only files
find . -mtime -7 # modified in last 7 days
find . -size +10M # files larger than 10MB
find . -name "*.tmp" -delete # find and delete
Permissions
chmod -> Change file permissions
chmod 755 script.sh # rwxr-xr-x
chmod +x script.sh # add execute permission
chmod -R 644 directory/ # recursive
Process management
ps -> List running processes
ps aux # all processes with details
ps -ef # full format listing
ps aux | grep node # filter specific process
ps -u username # processes of a specific user
kill / killall -> Terminate processes
kill PID # graceful termination (SIGTERM)
kill -9 PID # force kill (SIGKILL)
killall process_name # kill by name
kill -15 PID # same as default SIGTERM
Archiving
tar -> Archive and compress
tar -czvf archive.tar.gz folder/ # create gzip archive
tar -xzvf archive.tar.gz # extract
tar -tzvf archive.tar.gz # list contents
tar -cjvf archive.tar.bz2 folder/ # bzip2 compression
System resource monitoring
df -> Display disk space usage
df -h # human-readable sizes (GB/MB)
df -hT # show filesystem type
df -i # show inode usage
du -> Estimate file/directory space usage
du -sh folder/ # total size of a folder (summary)
du -h --max-depth=1 # size of each subfolder
du -ah # show all files and directories
free -> Display memory usage
free -h # human-readable
free -m # show in megabytes
free -s 5 # refresh every 5 seconds
uptime -> Show system uptime and load average
uptime -p # pretty format (“up 2 days, 3 hours”)
top -> Real-time overall system view
top # interactive view
Press M # sort by memory
Press P # sort by CPU
Press q # quit
vmstat -> System memory, processes, CPU, I/O stats
vmstat 1 # update every 1 second
vmstat -s # summary of memory statistics
vmstat -d # disk statistics
Process viewing
pstree -> Display processes in a tree structure
pstree # basic tree
pstree -p # show PIDs
pstree -u # show usernames
pstree -a # show command-line arguments
Command history
history -> View previously executed commands
history # full list
history 20 # last 20 commands
!123 # re-run command number 123
!! # re-run the last command
history | grep "docker" # search past commands
Top comments (0)