βΎοΈ DevOps and π§ Linux Commands: A Powerful Duoπ₯
Basics commands, Files and Directories operations
π Quick Intro
Linux is open source, which means it is free and you can make any changes in the source code and use your own Linux
Linux has multi-user support
Linux Torvalds used Unix OS to create his own OS, which is named Linux
It's essential to understand the fundamental Linux commands and how to use them effectively. This comprehensive guide will take you through a detailed exploration of these commands.
π Command Line Interface π§βπ»
CLI is like talking to a computer using special words (commands), you type in commands, and the computer does what you say. It's a bit like magic πͺ words to make your computer do things.
What does CLI look like?
let's see what is written in CLI
user name of logged-in user
computer name
~ is the home directory of logged-in user, which in this case is /home/ec2-user
# at the end represents the root user, like the admin user in Windows
$ at the end represents a normal user
pwd is a present working directory
π Types of files
Ordinary File / Normal File π
start with '-' in the
ls -l
commandcontains data like text, images, audio, video, etc.
Directory File [folder] π
start with 'd' in the
ls -l
commandcontains all kinds of files in it
Link File π
start with 'l' in the
ls -l
commandit is a link to another file
look at the first character of each line
π Let's start with Commands βοΈ
Basics commands βοΈ
pwd
- present working directory, the current location of a user in the file structurecd
- change directorywhoami
- it will display the current logged-in usernamewho
- shows logged-in users of the systemdate
- display current date with timecal
- display calendarhistory
- get all commands that are executed in the pasthistory n
- get only 'n' recent commands that are executed in the pastman <command>
- it will give documentation of the commandunzip <zip-file>
- extract the zip filetar -xvzf <tar-file>
- extract the tar file-
Create or delete files and directories π
touch <file>
- create an empty filetouch <file1> <file2> ...
- create multiple empty filestouch file{1..5}.txt ...
- create multiple empty files with numeric names as file1.txt file2.txt ... file5.txtcat > <file>
- create a file with data [ctrl+d to save and exit]cat >> <file>
- append file with data [ctrl+d to save and exit]cat <file>
- display data in the filemkdir <dir>
- create directorymkdir <dir1> <dir2>
- create multiple directoriesmkdir -p dir1/dir2/dir3/dir4
- create nested directoriesmkdir dir{1..5}.txt ...
- create multiple empty directories with numeric names as dir1.txt dir2.txt ... dir5.txtrm <file>
- delete filermdir <dir>
- delete an empty directoryrmdir <dir1> <dir2>
- delete multiple empty directoriesrm -d <dir>
- delete an empty directoryrm -r <dir>
- delete a non-empty directory -
File operations βοΈ
cat file1 > file2
- copy content of file1 to file2cat file1 file2 > file3
- copy content of file1 & file2 to file3cp file1 file2
- copy content of file1 to file2cp -r dir1 dir2
- copy all files from dir1 to dir 2mv file1 file2
- rename or move file or dircmp file1 file2
- display only the first differencediff file1 file2
- display all differences -
List files π
ls
- used to list files and dir in current dir [alphabetical order]ls <dir>
- used to list files and dir in a given dirπ© FLAGS
ls -l
- list files and dir with infols -r
- ordering files reversely alphabetical orderls -t
- list files and dir by ordering them based on modified date and timels -tr
- ordering files reversely based on modified date and timels -ltr
ls -a
- list hidden files alsols -R
- shows files and dir with subdirectories content -
Read file data and details βοΈ
wc <file>
- display no. of lines, words, and characters in the fileπ©FLAGS
-l
--> Display only the number of lines-w
--> Display only the number of words-c
--> Display only the number of characterscat <file>
- display the content of the filecat -n <file>
: display the content of a file with line numbertac <file>
: display the content of the file line-wise from bottom to toprev <file>
: each line in reverse order from top to bottomhead <file>
: display top lines of file [default is 10]head -n <number> <file>
: display top n linestail <file>
: display bottom lines of file [default is 10]tail -n <number> <file>
: display bottom n linestail -n +<number> <file>
: display lines from nth to lastgrep 'text' file
: display matched lines with the file namegrep 'text' *
: search text in all files in the current dirgrep -n 'text'
: display matched lines with line numbergrep -l 'text'
: display only file namegrep -L 'text'
: display file names that do not containgrep -v 'text'
: Invert the string matchgrep -i 'text' file
: search text in file [case insensitive]grep -R 'text'
: search text in all subdirectory filegrep ^text file
: display lines that start with a textgrep text$ file
: display lines that end with a text
These basic Linux commands provide you with a solid foundation for navigating and managing your Linux system. As you continue your journey with Linux, you'll discover additional commands and tools that will empower you to perform more advanced tasks and streamline your system administration and development activities. Linux's robust command-line interface offers endless possibilities for customization, automation, and control, making it a powerful and versatile platform for a wide range of use cases.
Happy Learning !!! π