0% found this document useful (0 votes)
15 views

Linux Commands To Practice

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Linux Commands To Practice

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

### 1.

`ls`
**Description:** Lists directory contents.
**Examples:**
- `ls` - Lists files and directories in the current directory.
- `ls -l` - Lists files and directories in long format.

### 2. `cd`
**Description:** Changes the current directory.
**Examples:**
- `cd /home/user` - Changes to the `/home/user` directory.
- `cd ..` - Moves up one directory level.

### 3. `pwd`
**Description:** Prints the current working directory.
**Examples:**
- `pwd` - Shows the full path of the current directory.
- `pwd -P` - Shows the physical directory, without symbolic links.

### 4. `cp`
**Description:** Copies files or directories.
**Examples:**
- `cp file1.txt file2.txt` - Copies `file1.txt` to `file2.txt`.
- `cp -r dir1 dir2` - Recursively copies `dir1` to `dir2`.

### 5. `mv`
**Description:** Moves or renames files or directories.
**Examples:**
- `mv file1.txt file2.txt` - Renames `file1.txt` to `file2.txt`.
- `mv dir1 /home/user/` - Moves `dir1` to `/home/user/`.
### 6. `rm`
**Description:** Removes files or directories.
**Examples:**
- `rm file1.txt` - Removes `file1.txt`.
- `rm -r dir1` - Recursively removes `dir1` and its contents.

### 7. `touch`
**Description:** Creates an empty file or updates the timestamp of an existing file.
**Examples:**
- `touch file1.txt` - Creates `file1.txt` if it doesn't exist.
- `touch -a -m file1.txt` - Updates access and modification times of `file1.txt`.

### 8. `mkdir`
**Description:** Creates a directory.
**Examples:**
- `mkdir newdir` - Creates a directory named `newdir`.
- `mkdir -p /path/to/dir` - Creates a directory with all intermediate directories.

### 9. `rmdir`
**Description:** Removes an empty directory.
**Examples:**
- `rmdir olddir` - Removes the directory named `olddir`.
- `rmdir --ignore-fail-on-non-empty dir1` - Removes `dir1` if it is empty, ignoring errors if it
is not.

### 10. `cat`


**Description:** Concatenates and displays file content.
**Examples:**
- `cat file1.txt` - Displays the content of `file1.txt`.
- `cat file1.txt file2.txt > combined.txt` - Combines `file1.txt` and `file2.txt` into
`combined.txt`.
### 11. `echo`
**Description:** Displays a line of text.
**Examples:**
- `echo "Hello, World!"` - Prints `Hello, World!` to the terminal.
- `echo $PATH` - Displays the value of the `PATH` environment variable.

### 12. `grep`


**Description:** Searches for patterns in files.
**Examples:**
- `grep "searchterm" file1.txt` - Searches for `searchterm` in `file1.txt`.
- `grep -r "searchterm" /path/to/dir` - Recursively searches for `searchterm` in the specified
directory.

### 13. `find`


**Description:** Searches for files in a directory hierarchy.
**Examples:**
- `find /path/to/dir -name "*.txt"` - Finds all `.txt` files in the specified directory.
- `find /path/to/dir -type f -size +1M` - Finds files larger than 1MB in the specified directory.

### 14. `chmod`


**Description:** Changes file permissions.
**Examples:**
- `chmod 755 file1.txt` - Sets read, write, and execute permissions for the owner, and read
and execute permissions for others.
- `chmod +x script.sh` - Adds execute permission to `script.sh`.

### 15. `chown`


**Description:** Changes file owner and group.
**Examples:**
- `chown user1 file1.txt` - Changes the owner of `file1.txt` to `user1`.
- `chown user1:group1 file1.txt` - Changes the owner to `user1` and the group to `group1`.

### 16. `ps`


**Description:** Displays information about running processes.
**Examples:**
- `ps` - Lists processes for the current user.
- `ps aux` - Lists all running processes with detailed information.

### 17. `top`


**Description:** Displays real-time system information, including processes.
**Examples:**
- `top` - Opens the top command interface showing running processes.
- `top -u user1` - Shows processes for `user1`.

### 18. `kill`


**Description:** Terminates processes.
**Examples:**
- `kill 1234` - Sends the default SIGTERM signal to the process with PID 1234.
- `kill -9 1234` - Forcefully kills the process with PID 1234.

### 19. `df`


**Description:** Displays disk space usage.
**Examples:**
- `df` - Shows disk space usage of all mounted filesystems.
- `df -h` - Shows disk space usage in human-readable format.

### 20. `du`


**Description:** Displays disk usage of files and directories.
**Examples:**
- `du /path/to/dir` - Shows disk usage of the specified directory.
- `du -sh /path/to/dir` - Shows a summarized and human-readable format of the disk usage.

### 21. `tar`


**Description:** Archives files.
**Examples:**
- `tar -cvf archive.tar /path/to/dir` - Creates an archive named `archive.tar` from the specified
directory.
- `tar -xvf archive.tar` - Extracts the contents of `archive.tar`.

### 22. `gzip`


**Description:** Compresses files using the gzip algorithm.
**Examples:**
- `gzip file1.txt` - Compresses `file1.txt` to `file1.txt.gz`.
- `gzip -d file1.txt.gz` - Decompresses `file1.txt.gz` to `file1.txt`.

### 23. `gunzip`


**Description:** Decompresses gzip-compressed files.
**Examples:**
- `gunzip file1.txt.gz` - Decompresses `file1.txt.gz` to `file1.txt`.
- `gunzip -c file1.txt.gz > file1.txt` - Decompresses `file1.txt.gz` and outputs to `file1.txt`.

### 24. `ssh`


**Description:** Connects to a remote machine via SSH.
**Examples:**
- `ssh user@remotehost` - Connects to `remotehost` as `user`.
- `ssh -i /path/to/key user@remotehost` - Connects to `remotehost` using the specified private
key.

### 25. `scp`


**Description:** Securely copies files between hosts.
**Examples:**
- `scp file1.txt user@remotehost:/path/to/dir` - Copies `file1.txt` to the specified directory on
`remotehost`.
- `scp user@remotehost:/path/to/file1.txt /local/path` - Copies `file1.txt` from `remotehost` to
the local directory.

### 26. `wget`


**Description:** Downloads files from the internet.
**Examples:**
- `wget http://example.com/file1.txt` - Downloads `file1.txt` from the specified URL.
- `wget -r http://example.com/` - Recursively downloads the entire website.

### 27. `curl`


**Description:** Transfers data from or to a server.
**Examples:**
- `curl http://example.com` - Fetches the content of the specified URL.
- `curl -o file1.txt http://example.com/file1.txt` - Downloads `file1.txt` from the specified
URL and saves it locally.

### 28. `nano`


**Description:** A simple text editor for the command line.
**Examples:**
- `nano file1.txt` - Opens `file1.txt` for editing in the nano editor.
- `nano +12 file1.txt` - Opens `file1.txt` and places the cursor at line 12.

### 29. `vim`


**Description:** A powerful text editor for the command line.
**Examples:**
- `vim file1.txt` - Opens `file1.txt` for editing in the vim editor.
- `vim +12 file1.txt` - Opens `file1.txt` and places the cursor at line 12.

### 30. `sudo`


**Description:** Executes a command with superuser privileges.
**Examples:**
- `sudo apt-get update` - Runs the `apt-get update` command as a superuser.
- `sudo systemctl restart apache2` - Restarts the Apache2 service as a superuser.

### 31. `apt-get`


**Description:** A package management tool for Debian-based systems.
**Examples:**
- `sudo apt-get install package_name` - Installs the specified package.
- `sudo apt-get remove package_name` - Removes the specified package.

### 32. `yum`


**Description:** A package management tool for RPM-based systems.
**Examples:**
- `sudo yum install package_name` - Installs the specified package.
- `sudo yum remove package_name` - Removes the specified package.

### 33. `systemctl`


**Description:** Controls

the systemd system and service manager.


**Examples:**
- `sudo systemctl start service_name` - Starts the specified service.
- `sudo systemctl stop service_name` - Stops the specified service.

### 34. `service`


**Description:** Controls services on the system.
**Examples:**
- `sudo service apache2 start` - Starts the Apache2 service.
- `sudo service apache2 stop` - Stops the Apache2 service.
### 35. `reboot`
**Description:** Reboots the system.
**Examples:**
- `sudo reboot` - Reboots the system immediately.
- `sudo reboot -f` - Forcefully reboots the system.

### 36. `shutdown`


**Description:** Shuts down or reboots the system.
**Examples:**
- `sudo shutdown now` - Shuts down the system immediately.
- `sudo shutdown -r now` - Reboots the system immediately.

### 37. `history`


**Description:** Shows the command history.
**Examples:**
- `history` - Lists all previously executed commands.
- `history | grep command` - Searches the command history for `command`.

### 38. `alias`


**Description:** Creates shortcuts for commands.
**Examples:**
- `alias ll='ls -l'` - Creates an alias `ll` for `ls -l`.
- `alias grep='grep --color=auto'` - Creates an alias for `grep` with color highlighting.

### 39. `unalias`


**Description:** Removes an alias.
**Examples:**
- `unalias ll` - Removes the `ll` alias.
- `unalias -a` - Removes all aliases.
### 40. `man`
**Description:** Displays the manual page for a command.
**Examples:**
- `man ls` - Shows the manual page for the `ls` command.
- `man -k keyword` - Searches the manual pages for `keyword`.

You might also like