Linux commands are used to perform tasks such as file management, process control, and system navigation. Commands are entered in the terminal, and understanding their usage is critical for efficient Linux usage.
Basic Linux Commands
1. Navigation Commands
These commands help you move around the Linux file system:
-
pwd
: Displays the current working directory. -
ls
: Lists files and directories in the current directory.-
Options:
-
ls -a
: Shows all files, including hidden ones. -
ls -l
: Provides a detailed list.
-
-
-
cd [directory]
: Changes the current directory to the specified one.-
Example:
cd /home/user
.
-
-
cd ..
: Moves up one directory level.
2. File and Directory Management
Commands to create, delete, and manipulate files and directories:
-
mkdir [directory_name]
: Creates a new directory.-
Example:
mkdir my_folder
.
-
-
touch [file_name]
: Creates an empty file.-
Example:
touch newfile.txt
.
-
-
rm [file_name]
: Deletes a file.-
Example:
rm oldfile.txt
. -
To delete directories:
rm -r [directory_name]
.
-
-
mv [source] [destination]
: Moves or renames files and directories.-
Example:
mv file1.txt /home/user/documents
.
-
-
cp [source] [destination]
: Copies files or directories.-
Example:
cp file1.txt backup_file.txt
.
-
3. Viewing and Editing Files
Commands to view and modify file contents:
-
cat [file_name]
: Displays the contents of a file.-
Example:
cat notes.txt
.
-
-
less [file_name]
: Views file content one screen at a time. -
nano [file_name]
: Opens a text editor to modify a file.-
Example:
nano config.txt
.
-
4. File Permissions and Ownership
Manage access and ownership of files and directories:
-
chmod [permissions] [file_name]
: Changes file permissions.-
Example:
chmod 644 file.txt
.
-
-
chown [owner] [file_name]
: Changes the ownership of a file.-
Example:
chown user1 file.txt
.
-
5. Process Management
Monitor and control running processes:
-
ps
: Lists running processes. -
top
: Displays an interactive view of running processes and system resource usage. -
kill [PID]
: Stops a process by its Process ID.-
Example:
kill 1234
.
-
6. System Information
Retrieve details about the system:
-
uname -a
: Displays system information. -
df -h
: Shows disk space usage. -
free -h
: Displays memory usage. -
uptime
: Provides system uptime information.
7. Package Management (for Debian-based systems like Ubuntu)
Install, update, and remove software:
-
sudo apt update
: Updates the package list. -
sudo apt upgrade
: Installs updates for packages. -
sudo apt install [package_name]
: Installs a package.-
Example:
sudo apt install curl
.
-
-
sudo apt remove [package_name]
: Removes a package.
Combining Commands
Linux supports chaining multiple commands for efficiency:
-
&&
: Runs the next command only if the previous one succeeds.-
Example:
mkdir new_folder && cd new_folder
.
-
-
|
(Pipe): Passes the output of one command as input to another.-
Example:
ls | grep txt
(Lists files containing “txt”).
-