Linux shell commands are used to interact with the Linux operating system through the command-line interface (CLI). They allow you to perform various tasks, manage files and directories, configure system settings, and more. Here's an explanation of some common Linux shell commands:
-
ls
(List):- Used to list files and directories in the current directory.
- Example:
ls
,ls -l
(long format),ls -a
(include hidden files),ls /path/to/directory
(list a specific directory).
-
cd
(Change Directory):- Used to change the current working directory.
- Example:
cd /path/to/directory
,cd ..
(move up one directory),cd ~
(go to the user's home directory).
-
pwd
(Print Working Directory):- Displays the current working directory's path.
- Example:
pwd
.
-
touch
(Create Empty File):- Creates an empty file with the specified name.
- Example:
touch filename.txt
.
-
mkdir
(Make Directory):- Creates a new directory with the specified name.
- Example:
mkdir directory_name
.
-
rmdir
(Remove Directory):- Deletes an empty directory.
- Example:
rmdir directory_name
.
-
rm
(Remove):- Used to delete files and directories.
- Be cautious when using
rm
with the-r
flag, as it can delete directories and their contents recursively. - Example:
rm filename.txt
,rm -r directory_name
.
-
cp
(Copy):- Copies files or directories from one location to another.
- Example:
cp file1.txt /path/to/destination
,cp -r dir1/ dir2/
(recursively copy directories).
-
mv
(Move/Rename):- Moves files or directories to a different location or renames them.
- Example:
mv file1.txt /path/to/destination
,mv old_name new_name
.
-
cat
(Concatenate and Display):- Used to display the contents of a file.
- Example:
cat filename.txt
.
-
less
andmore
(File Viewing):- Display the contents of a file one screen at a time, allowing you to navigate through it.
- Example:
less filename.txt
,more filename.txt
.
-
head
andtail
(View Top/Bottom of a File):- Display the first (head) or last (tail) lines of a file.
- Example:
head -n 10 filename.txt
(display the first 10 lines),tail -n 20 filename.txt
(display the last 20 lines).
-
grep
(Global Regular Expression Print):- Searches for patterns or text within files.
- Example:
grep "pattern" filename.txt
.
-
chmod
(Change File Permissions):- Modifies file permissions to control who can read, write, and execute the file.
- Example:
chmod 644 filename.txt
(read-write for owner, read-only for group and others).
-
chown
(Change Owner):- Changes the owner of a file or directory.
- Example:
chown new_owner:group filename.txt
.
-
ps
(Process Status):- Displays a list of currently running processes.
- Example:
ps aux
.
-
kill
(Terminate a Process):- Used to send signals to processes to stop or restart them.
- Example:
kill process_id
.
-
df
(Disk Free):- Shows information about disk space usage on mounted filesystems.
- Example:
df -h
(human-readable output).
-
du
(Disk Usage):- Displays the disk usage of files and directories.
- Example:
du -sh /path/to/directory
(summarize usage in a human-readable format).
-
history
(Command History):- Lists the previously executed shell commands.
- Example:
history
,history | grep keyword
(search command history).
These are just a few common Linux shell commands, and there are many more available for various tasks and system administration purposes. Learning how to use these commands effectively can greatly enhance your ability to work with Linux systems. Additionally, you can use the man
command (e.g., man ls
) to access the manual pages for specific commands and learn more about their options and usage.