Linux, a powerful and versatile operating system, is known for its robust command-line interface. Here's a comprehensive guide to some fundamental Linux commands that you'll find useful whether you are a beginner or an advanced user. The commands can be entered in the terminal, which is Linux's command-line interface.
pwd
- Print Working Directory. Shows the current directory you are in.ls
- Lists all files and folders in the current directory.ls -l
- Provides detailed information including permissions, number, owner, size, and date of last modification.ls -a
- Lists all entries including hidden files starting with '.'.
cd
- Change Directory.cd ..
- Moves up one directory.cd ~
- Takes you to your home directory.
whoami
- Displays the current user logged in.man [command]
- Shows the manual for the specified command.
touch [file]
- Creates a new file or updates the timestamp on an existing file.cp [source] [destination]
- Copies files or directories.cp -r [source_directory] [destination_directory]
- Copies directories recursively.
mv [source] [destination]
- Moves or renames files or directories.rm [file]
- Removes a file.rm -r [directory]
- Recursively removes a directory and all its contents.
mkdir [directory]
- Creates a new directory.rmdir [directory]
- Removes an empty directory.
cat [file]
- Displays the content of a file on the terminal.less [file]
- Views the content of a file one page at a time.head [file]
- Displays the first 10 lines of a file (customizable with-n
option).tail [file]
- Displays the last 10 lines of a file (also customizable).nano [file]
- Opens the nano editor with the specified file.vi [file]
- Opens the vi/vim editor with the specified file.
top
- Displays an ongoing view of all running processes.ps
- Lists snapshots of current processes.ps aux
- Shows detailed information about all running processes.
df
- Reports the amount of disk space used and available on filesystems.df -h
- Shows the disk space in human-readable format.
free
- Shows the amount of free and used memory in the system.free -h
- Outputs the information in human-readable format.
ping [address]
- Checks connectivity between the host and the target address.ifconfig
- Displays network interface configuration and can also set up an interface.wget [URL]
- Downloads files from the internet.curl [URL]
- Transfers data from or to a server.ssh [user@host]
- Connects to a remote host via Secure Shell.
sudo [command]
- Executes a command with superuser privileges.apt-get update
andapt-get upgrade
- Updates package list and upgrades all packages respectively (specific to Debian-based systems like Ubuntu).chmod [permissions] [file]
- Changes the file permissions.chown [owner]:[group] [file]
- Changes the owner and/or group of a file.
grep [pattern] [file]
- Searches for a specific pattern in the file's content.find [directory] -name [search_pattern]
- Finds files and directories based on a pattern.sort [file]
- Sorts the contents of a file.
These commands are just the basics to get you started with Linux. There are countless more commands and options to explore depending on what you need to achieve. For specific tasks or advanced functionality, referring to the manual pages (man command
) is highly recommended.