0% found this document useful (0 votes)
6 views1 page

Essential Linux Commands Guide

Uploaded by

Abdullahkhasib
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Essential Linux Commands Guide

Uploaded by

Abdullahkhasib
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

pwd : to show the current path

cd (path or file): to change directory


cd .. or exit : to go back a directory (cd ../.. for 2 etc)
sudo su : to enter the root and (exit) to leave it
echo : to print any text
whoami : to show who is the current user
ls (-a for hidden) (-l for details): to list the items in the desired directory
ls /usr/sharee/wordlists/ : shows texts that possibly contain passwords
cat : shows whats in a text file
ctrl C (^C) : to quit to terminal command
man : to show the manual for the command
mkdir : to creat a directory
rmdir : remove an emtpy directory
touch : create a file
cp : copy a file or directory
clear : to clear the terminal page
nano : is a text editor
mv : to rename a file or to move it to another directory
file : show the file type
rm : remove a file
& : allows you run commands in the back
&& : allows you to combine multiple commands in one line
| : use the output of a command as in input for another
|| : excute the command thats after only if the one before failed
kill : to terminate a command in the background
ps : to show running commands
sleep : makes the terminal sleep for a certain time
> : redirect output to the chosen file while deleting its content
>> : adds redirected output to the file without deleting its contents
2> : to store any error on the terminal in a file

* : to print all the contents


; : to use continous multiple commands
# : for comments
? : to guess unsure characters
grep : search the contents of a file for specific values
find : search for files in a directory
which : locate a command
locate : same as find but weaker
chmod : change the permission of the file or directory
useradd : add a user

Common questions

Powered by AI

The 'chmod' command changes the permissions of files and directories, affecting who can read, write, or execute them. Proper use of 'chmod' is critical for system security, as incorrect permissions can lead to unauthorized access or modification. For instance, setting a script as executable ('chmod +x') is necessary for it to run, but overly permissive settings (e.g., world-writable files) can be a security risk. Strategically using 'chmod' helps secure sensitive data and control access, which is especially pertinent in multi-user environments or servers .

The 'find' command searches for files by traversing the file hierarchy, and it is known for being more comprehensive and versatile. It can search for files in a specific directory and its subdirectories based on a variety of criteria such as name, type, or modification time. On the other hand, the 'locate' command searches for files by querying a database that holds pre-indexed metadata about files on the system, which makes it faster but less dynamic as it may not reflect the most current file system state .

The '&&' operator is used to combine multiple commands, executing the second command only if the first command succeeds (i.e., returns an exit status of 0). In contrast, the '||' operator is used to execute the second command only if the first command fails (i.e., returns a non-zero exit status). This logical distinction allows users to handle different scenarios: for example, '&&' can chain commands that depend on each other's success, while '||' sets up contingency commands for handling failures. Understanding these implications is critical for creating robust shell scripts .

The 'sudo su' command allows a user to switch to the root user account, providing access to administrative privileges and the ability to execute commands as root. This is significant in system administration, as it grants full control over the system, enabling critical tasks like installation, configuration, or file access changes that regular users cannot perform. However, improper or excessive use of 'sudo su' can compromise system security, highlighting the need for controlled and cautious usage .

The '&' operator is used to run commands in the background, allowing the terminal to accept additional commands without waiting for the previous one to finish. This is crucial for multitasking and efficient resource use. In contrast, parentheses '(' and ')' group commands to run them in a subshell, which can be executed in the background by appending '&'. While '&' simplifies background execution, parentheses provide more control by creating isolated environments. Each has distinct advantages based on execution requirements and resource management .

The 'echo' command is used to print text, and when combined with the '>' operator, the output of 'echo' can be redirected to a file. This combination overwrites the file's existing content with the specified text. For example, 'echo "Hello, World!" > file.txt' would replace any content in 'file.txt' with 'Hello, World!'. This is useful for creating new content or resetting the file's content .

'grep' offers significant advantages in searching file contents by allowing users to quickly locate lines that match a given pattern or string. It efficiently processes large files and directories, delivering results far faster than manual searching. Key features include search through patterns using regular expressions and coloring of matched results for better visibility. This enhances productivity, especially in environments where time and accuracy are critical .

The 'ps' command displays information about currently running processes, including details such as PID (process ID), TTY, time, and command names. This information is crucial for process management, allowing users to identify and monitor specific processes. When used in conjunction with the 'kill' command, which terminates processes, 'ps' can be used first to find the PID of a process, followed by 'kill <PID>' to terminate it. This combination is essential for managing processes effectively, especially when dealing with unresponsive or unnecessary applications .

The 'touch' command is used to create an empty file or update the timestamp of existing files. It is useful for quickly initializing files for scripting or configuration. Conversely, 'mkdir' is used to create directories, organizing files into hierarchies. Practically, 'touch' is implemented when individual files are required, while 'mkdir' is crucial for structuring and managing directories. Understanding these applications is vital for efficient file system management, balancing file creation with organizational structure .

'nano' is a text editor that allows users to create and modify text files interactively with features like text navigation and editing. In contrast, 'cat' is used to display the contents of a text file but does not allow editing. While 'cat' is favored for simply viewing content quickly, 'nano' is preferred when interactive editing is required due to its comprehensive editing capabilities. This distinction makes 'nano' preferable in scenarios needing modification or creation of text files .

You might also like