Table of contents
No headings in the article.
As a DevOps professional, you'll frequently work with Linux systems and utilize various commands to manage and automate tasks. Here are some commonly used Linux commands along with explanations and examples:
ls: This command lists files and directories in the current directory.
Example:
ls -l
lists files and directories in long format with detailed information.ls -l
--> list the files and directories in long list format with extra informationls -a
--> list all including hidden files and directoryls *.sh
--> list all the files having .sh extension.ls -i
--> list the files and directories with index numbers inodesls -d */
--> list only directories.(we can also specify a pattern)
cd: Used to change the current directory.
Example:
cd /var/www
changes the current directory to "/var/www".pwd
--> print work directory. Gives the present working directory.cd path_to_directory
--> change directory to the provided pathcd ~
or justcd
--> change directory to the home directorycd -
--> Go to the last working directory.cd ..
--> change directory to one step back.cd ../..
--> Change directory to 2 levels back.
pwd: Prints the current working directory.
- Example:
pwd
displays the current directory path.
- Example:
mkdir: Creates a new directory.
Example:
mkdir project
creates a directory named "project".mkdir directoryName
--> to make a directory in a specific locationmkdir directoryName
# make a new folder 'newFolder'mkdir NewFolder # make a hidden directory (also . before a file to make it hidden)
mkdir A B C D #make multiple directories at the same time
mkdir /home/user/Mydirectory # make a new folder in a specific location
mkdir -p A/B/C/D # make a nested directory
rm: Removes files and directories.
Example:
rm file.txt
deletes a file named "file.txt".Example:
rm -r directory
deletes a directory and its contents recursively.
cp: Copies files and directories.
- Example:
cp file.txt /tmp
copies "file.txt" to the "/tmp" directory.
- Example:
mv: Moves or renames files and directories.
Example:
mv file.txt newfile.txt
renames "file.txt" to "newfile.txt".Example:
mv file.txt /tmp
moves "file.txt" to the "/tmp" directory.
touch: Creates an empty file or updates the access and modification timestamps of an existing file.
- Example:
touch file.txt
creates an empty file named "file.txt".
- Example:
cat: Displays the contents of a file.
- Example:
cat file.txt
outputs the content of "file.txt" to the console.
- Example:
grep: Searches for a specified pattern in files.
- Example:
grep "error" logfile.txt
searches for the word "error" in "logfile.txt".
- Example:
chmod: Modifies file permissions.
chown: Changes the owner of a file or directory.
- Example:
chown user:group file.txt
changes the owner and group of "file.txt".
- Example:
ssh: Connects to a remote machine using the Secure Shell protocol.
- Example:
ssh user@hostname
establishes an SSH connection to "hostname" as "user".
- Example:
scp: Securely copies files between local and remote systems using SSH.
- Example:
scp file.txt user@hostname:/path
copies "file.txt" to the remote machine at "/path".
- Example:
wget: Downloads files from the web.
- Example:
wget
https://example.com/file.zip
downloads "file.zip" from the given URL.
- Example:
These commands are just a starting point, and there are many more available in Linux. Their usage may vary depending on your specific requirements and the tasks you need to accomplish as a DevOps professional.
Hope this is useful for you :)