Common Linux Commands and Descriptions
Linux FileSystem Structure
/
โโโ bin/ # Essential user binaries (e.g., ls, cat), accessible by all users.
โโโ boot/ # Files needed to boot the system, like the kernel and bootloader configs.
โโโ dev/ # Device files representing hardware (e.g., /dev/sda for hard drives).
โโโ etc/ # System-wide configuration files (e.g., fstab, hosts).
โ โโโ init.d/ # Service scripts (start, stop, restart)
โ โโโ nginx/ # Configuration for the nginx web server
โ โโโ ssh/ # SSH configuration files
โโโ home/ # User home directories for personal data.
โ โโโ user/ # Directory for user 'user',
โโโ lib/ # Shared libraries essential for the system and kernel modules.
โโโ media/ # Mount points for removable media, external devices like USBs or DVDs.
โโโ mnt/ # Temporary mount directory
โโโ opt/ # Optional software packages or third-party apps.
โโโ proc/ # Process and kernel information
โโโ root/ # Home directory for root user
โโโ sbin/ # System binaries for administrative tasks (e.g., reboot, iptables).
โโโ tmp/ # Temporary files, often cleared on reboot.
โโโ usr/ # User programs and libraries, typically for installed packages.
โ โโโ bin/ # User commands
โ โโโ lib/ # User libraries
โ โโโ share/ # Shared files
โโโ var/ # Variable files (logs, databases, etc.)
โโโ log/ # Log files
โโโ cache/ # Application cache data
โโโ tmp/ # Temporary files created by applications
File and Directory Operations
-
ls
โ Lists the contents of a directory.
ls ls -l # Long listing format ls -a # List all files, including hidden ones
-
cd
โ Changes the current directory.
cd /path/to/directory cd .. # Go up one directory cd ~ # Go to the home directory
-
mkdir
โ Creates a new directory.
mkdir new_directory
-
rmdir
โ Removes an empty directory.
rmdir directory_name
-
cp
โ Copies files or directories.
cp source_file destination cp -r source_directory destination_directory # Copy directories recursively
-
mv
โ Moves or renames files and directories.
mv old_name new_name mv file_name /path/to/destination/
-
rm
โ Removes files or directories.
rm file_name rm -r directory_name # Remove directories recursively
-
touch
โ Creates an empty file or updates the timestamp of an existing file.
touch file_name
File Viewing & Manipulation
-
cat
โ Displays the contents of a file.
cat file_name
-
less
โ Allows you to view file contents page by page.
less file_name
-
head
โ Shows the first 10 lines of a file (default).
head file_name head -n 5 file_name # Show the first 5 lines
-
tail
โ Shows the last 10 lines of a file (default).
tail file_name tail -n 5 file_name # Show the last 5 lines
-
grep
โ Searches for patterns within files.
grep 'search_term' file_name grep -r 'search_term' /path/to/directory # Search recursively in directories
Permissions & Ownership
-
chmod
โ Changes file permissions.
chmod 755 file_name # Gives read, write, execute permissions to the owner and read, execute to others chmod +x script.sh # Make file executable
-
chown
โ Changes the file owner and group.
chown user:group file_name
-
umask
โ Sets default file creation permissions.
umask 022 # Sets default permissions to 755 for directories and 644 for files
Process Management
-
ps
โ Displays the currently running processes.
ps ps aux # Show all processes
-
top
โ Displays real-time system processes and resource usage.
top
-
kill
โ Terminates a process by its PID.
kill process_id kill -9 process_id # Forcefully kill a process
-
htop
โ Interactive process viewer (requires installation).
htop
System Information
-
df
โ Shows disk space usage.
df -h # Human-readable format
-
du
โ Shows disk usage for files and directories.
du -h /path/to/directory
-
free
โ Displays memory usage.
free -h # Human-readable format
-
uname
โ Shows system information.
uname -a # Display all system info
-
uptime
โ Shows how long the system has been running.
uptime
-
whoami
โ Displays the current logged-in user.
whoami
-
hostname
โ Displays or sets the system's hostname.
hostname
-
lscpu
โ Displays CPU architecture information.
lscpu
Network Commands
-
ping
โ Tests connectivity to a host.
ping google.com
-
ifconfig
โ Displays network interface information (may require net-tools installation on some systems).
ifconfig
-
ip
โ Configures network interfaces and routing.
ip addr show # Show IP addresses of network interfaces ip route show # Show routing table
-
curl
โ Fetches data from a URL.
curl https://example.com
-
wget
โ Downloads files from the web.
wget https://example.com/file.zip
Package Management
-
apt-get
(for Debian/Ubuntu-based distributions) โ Installs, updates, or removes software packages.
sudo apt-get update # Update package list sudo apt-get install package # Install a package sudo apt-get remove package # Remove a package
-
yum
(for RedHat/CentOS-based distributions) โ Installs, updates, or removes software packages.
sudo yum update # Update package list sudo yum install package # Install a package sudo yum remove package # Remove a package
File Compression
-
tar
โ Archives or extracts files.
tar -czvf archive_name.tar.gz /path/to/directory # Create a compressed archive tar -xzvf archive_name.tar.gz # Extract a compressed archive
-
zip
โ Compresses files into a zip archive.
zip archive_name.zip file1 file2
-
unzip
โ Extracts a zip archive.
unzip archive_name.zip
Miscellaneous
-
echo
โ Prints a message or variables to the terminal.
echo "Hello, World!"
-
date
โ Displays or sets the system date and time.
date
-
alias
โ Creates an alias for a command.
alias ll='ls -la' # Create a shortcut for 'ls -la'
-
history
โ Shows the command history.
history
-
clear
โ Clears the terminal screen.
clear
These are just a few of the many powerful commands in Linux, but they cover most of the common operations you'll perform daily.
If you found this helpful, let me know by leaving a ๐ or a comment!, or if you think this post could help someone, feel free to share it! Thank you very much! ๐
Top comments (0)