I am learning DevOps for a while and I will be writing about everything I learn, which will eventually be beneficial for the community and aspiring DevOps learners.
I previously wrote about YAML which is very important for the DevOps journey have a look here.
Prerequisite
- *1. A Linux terminal *
- 2. Enthusiasm for learning
For setting up Ubuntu in windows terminal head over to this article officially by Ubuntu.
Okk...Let's start with shell, this is the place where we write our commands but what it is??
A shell is a command-line interface that will take all our command as input, interprets them, and converts them into useful things.
For some commands I have not included screenshot as they have to done by self.
Here's an image of what shell looks like.
Shells are of many types like Bourne shell,c-shell,z-shell, etc but here we won't discuss that as it is a very different topic, but as always you can head over here to know about it.
Let's deep dive with the commands -
- $ clear
``` - Clears the shell.
-
$ ls
- This command lists all files and folders in the current directory.
- ```
$ mkdir
``` - Makes new folder
- $ cd - This one changes the directory if we write ```
cd ..
``` then this takes us one folder back.
$ whereis - This gives the exact directory of any file.
$ xdg-open - Opens particular directory.
$ ls -a - Shows hidden files and folders.
- $ pwd - This prints the current working directory.
. -> current directory
.. -> previous directory
- $ ls -l - Gives more arguments like writable, readable, and executable state of the file, permission, and stuff.
$ ls -R - Lists all-recursive folder i.e folder inside folder .... and so on
$ cat - This outputs the content of a file.
If there is no file then $ cat > hello.txt can be used to make a file and give inputs to it.
Also $ cat file.txt hello.txt > sumit.txt can be used to replace the content of sumit.txt with the other two.
$ echo "Hello World" > file.txt this replaces all content of file.txt with Hello-World.
- $ man - This command gives information about a particular command. If you specify $ man sudo in the terminal you will get something like this ๐
- $ touch - touch command create a new file.
$ touch new.txt
- $ cp - copy contents of one file to another.
cp file.txt newFile.txt
- $ mv - this can rename as well as move a file.
mv fike.txt newName.txt (This renames)
mv file.txt usr/local/bin (This copies)
- $ rm - Remove a file
rm file.txt
- $ rmdir - Removes a directory only if it is empty.
$ rmdir
$ sudo - This command gives administrative privileges, if you are a Linux user you may be fully aware of it.
$ df - gives a capacity of the disk.
df -m (Size in Megabytes)
df -k (Size in Kilobytes)
df -h (In human-readable form)
- $ du - This gives disk usage statistics.
du -l
du -h (In human-readable form)
- $ head - Used to vies first few lines of any file, by default, it's 10.
As you can see after using the head command it's only showing 10 lines.
$ tail command shows the last few lines.
$ diff - This differentiate content of a file.
$ locate ** - This locates any file. **$ locate ".txt" this will locate all the files which have .txt extension.
$ whoami - Displays username.
- *File Permissions - * There are 3 file permissions Read, Write and Execute
$ chmod is the command to change file permissions.
*Performing action on multiple files *
If you wanna let's say remove multiple files at once then use:-
$ find . -type f -name "*.txt" -exec rm -rf {} +
basically {} is the placeholder and rm shows that remove these.
- $ grep - Global regular expression print, grep allows to look for particular text in the file. GREP is case-sensitive. I have made a text file that contains names of different random people and applied the following commands ๐
$ grep "Kunal" names.txt
$ grep -w "Kunal" names.txt
``` (Shows complete word)
$ grep -i "kunal" names.txt
``` (shows case sensitive names too)
$ grep -iw "kunal" names.txt
``` (shows case sensitive names with word specified)
![Screenshot (15).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1643281349556/Rz4x2zYHC.png)
$ grep -n "Kunal" names.txt
``` (Shows line number)
$ grep -win "Rahul" names.txt
``` (Combined with the word, case sensitive, and line number)
$ grep -b 3 "Rahul" ./.*txt"
``` (WIll search for Rahul in all txt files)
$ grep -rwin "Rahul" ./.*txt
``` (Will search recursively in all directories)
![Screenshot (16).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1643281962227/9b3S-V2b_.png)
**Terminal Shortcuts** -
1. *Ctrl + A* - Moves the cursor to begin.
2. *Ctrl + E* - Moves the cursor to end.
3 *Ctrl + U* - Removes Everything written.
4. *Ctrl + K* - Removes a word after the cursor.
5. *Up and Down Keys* - Previous commands.
6. *$ !<Previous_Command>* - With ! sign it will run the previous command.
7. *$ command_1;command_2;command_3* - Multiple commands with semi-colon.
8. *$ sort names.txt* - will sort in Ascending order.
9. *$ sort -r names.txt* - will sort all the names in reverse order.
10. *$ jobs* - displays current job.
11. *$ ping <url>* - Check your server.
12. *$ wget <URL>* - Download file.
13. *$ top* - shows all the running processes.
14 . *$ kill <process_id>* - Kills the running process.
15. *$ zip file_name.zip file_to_be_zipped* - Zips the file
if this doesn't work then use ```
$ sudo apt install zip
``` (installs package). Multiple files can be zipped.
16. *$ unzip file_name.zip* - Unzipes the file
17. *$ hostname* - Displays hostname.
18. *$ hostname -i* - Displays IP too
19. *$ uname* - Gives OS name
20. *$ uname -m* - Gives Architecture of os.
20. *$ uname -r* - Gives Kernal version.
21. *$ cat /etc/os-release* - Gives Operating System Info.
22. *$ free -h* - Displays free memory.
**Networking Commands - **
- ```
$ nslookup google.com
``` - Gives IP address of the particular site, here google.com .
- ```
$ netstat
``` - Looks all active stat.
**Some more useful commands - **
- ```
$ cut -c 1-2 names.txt
``` - Gives names after cutting two letters and we can specify the condition as we need.
![Screenshot (18).png](https://cdn.hashnode.com/res/hashnode/image/upload/v1643290282731/n5NuTAjSh.png)
- ```
$ ps aux
- Gives all the processes and it'd ids.
So this was it from my side and there are tons of commands but you will get everything while learning. Things will come naturally.
If you have read till here..then thanks.
Keep Learning๐๐
Top comments (0)