Linux-1 3
Linux-1 3
rwxr-xr-x, where each character defines the type of file and the permissions for
the owner, group, and others.
Each file or directory has these permissions for three types of users:
Owner – The user who owns the file.
Group – The group of users that the file belongs to.
Others – Everyone else who is not the owner or in the group.
Add permission:
chmod +x filename # Adds execute permission
chmod +r filename # Adds read permission
chmod +w filename # Adds write permission
Remove permission:
chmod -x filename # Removes execute permission
chmod -r filename # Removes read permission
chmod -w filename # Removes write permission
For example, to set rwx for owner, r-x for group, and r-- for others (i.e., 755),
use:
chmod 755 filename
To set rw- for owner, r-- for group, and r-- for others (i.e., 644), use:
chmod 644 filename
Set exact permission (symbolic method): You can also use symbolic notation to set
permissions:
chmod u+x filename # Add execute permission for the owner
chmod g-w filename # Remove write permission for the group
chmod o=r filename # Set read permission for others
1. cp
Usage: cp (copy files and directories)
What it does: Copies files or directories.
Example:
cp file1.txt /home/user/ → Copies file1.txt to /home/user/.
cp -r folder1 /home/user/ → Copies the entire directory folder1 recursively.
2. mv
Usage: mv (move or rename files)
What it does: Moves files or directories, or renames them.
Example:
mv file1.txt newfile.txt → Renames file1.txt to newfile.txt.
mv file1.txt /home/user/ → Moves file1.txt to /home/user/.
3. rm
Usage: rm (remove files or directories)
What it does: Deletes files or directories.
Example:
rm file1.txt → Removes file1.txt.
rm -r folder1 → Removes the folder1 directory and its contents.
4. mkdir
Usage: mkdir (make directories)
What it does: Creates a new directory.
Example:
mkdir newfolder → Creates a directory named newfolder.
5. rmdir
Usage: rmdir (remove empty directories)
What it does: Removes empty directories.
Example:
rmdir emptyfolder → Removes the empty directory emptyfolder.
6.man
Usage: man (manual pages)
What it does: Displays the manual (help) page for a command.
Example:
man ls → Shows the manual page for the ls command.
9. grep
Usage: grep (search text using patterns)
What it does: Searches for a pattern in a file or output.
Example:
grep "pattern" file.txt → Searches for the word "pattern" in file.txt.
ps aux | grep apache → Finds all running processes related to Apache.
10. find
Usage: find (search for files in a directory hierarchy)
What it does: Searches for files and directories based on conditions like name,
size, or type.
Example:
find /home/user/ -name "*.txt" → Finds all .txt files in /home/user/.
find /var/log/ -type f -size +100M → Finds files in /var/log/ that are larger than
100MB.
11. chmod
Usage: chmod (change file permissions)
What it does: Changes the read, write, and execute permissions of files and
directories.
Example:
chmod 755 file.sh → Gives read, write, execute permissions to the owner and read,
execute permissions to others.
chmod u+x script.sh → Adds execute permission to the owner of script.sh.
12. chown
Usage: chown (change file owner and group)
What it does: Changes the owner and/or group of a file or directory.
Example:
chown user:group file.txt → Changes the owner of file.txt to user and the group to
group.
13. ps
Usage: ps (process status)
What it does: Displays information about running processes.
Example:
ps → Lists processes running in the current terminal.
ps aux → Shows all running processes on the system.
14. top
Usage: top (task manager)
What it does: Displays real-time information about system processes and resource
usage (CPU, memory).
Example:
top → Opens a real-time view of processes and their resource usage.
15. kill
Usage: kill (terminate a process)
What it does: Sends a signal to a process, typically to terminate it.
Example:
kill 1234 → Terminates the process with PID 1234.
kill -9 1234 → Forces termination of process 1234 immediately.
16. df
Usage: df (disk space usage)
What it does: Shows available disk space on mounted filesystems.
Example:
df -h → Displays disk space in a human-readable format (e.g., GB, MB).
17. du
Usage: du (disk usage)
What it does: Shows the disk space used by files and directories.
Example:
du -sh /home/user/ → Shows the total disk usage of the /home/user/ directory.
18. tar
Usage: tar (archive files)
What it does: Creates or extracts compressed archive files (usually .tar, .tar.gz,
or .tar.bz2).
Example:
tar -cvf archive.tar file1.txt file2.txt → Creates a tar archive archive.tar with
the files file1.txt and file2.txt.
tar -xvf archive.tar → Extracts the contents of archive.tar.
19. wget
Usage: wget (download files from the web)
What it does: Downloads files from the internet using HTTP, HTTPS, or FTP.
Example:
wget https://example.com/file.zip → Downloads file.zip from the specified URL.
21. echo
Usage: echo (display a message or output text)
What it does: Prints text or variables to the screen.
Example:
echo "Hello, World!" → Prints "Hello, World!" on the screen.
22. history
Usage: history (view command history)
What it does: Displays a list of previously run commands in the terminal.
Example:
history → Shows the list of commands you've entered in the terminal.
23. alias
Usage: alias (create custom command shortcuts)
What it does: Creates a shortcut for a command.
Example:
alias ll='ls -l' → Creates an alias ll for ls -l.
24. uname
Usage: uname (system information)
What it does: Displays information about the system, like kernel version,
architecture, etc.
Example:
uname -a → Shows all available system information.
25. sudo
Usage: sudo (execute a command as another user, typically root)
What it does: Allows a permitted user to execute a command as the superuser or
another user.
Example:
sudo apt update → Runs the apt update command with superuser privileges.
sudo rm -rf / → WARNING! This would delete everything on your system (use with
caution).