Basic_linux_commands
Basic_linux_commands
✍ history
✍ pwd
pwd: It stands for print working directory. It prints the current
working directory in which the user currently is.
⫸ File Operations 📁
✍ touch
✍ cat
✍ cp
✍ mv
⫸ Text Processing 📋
✍ grep
grep [options] [pattern] [filename] : ‘globally search for a regular expression
and print’. It is used for text search and filtering based on regular
expressions and returns the lines which match the pattern.
• grep "INFO" logfile.txt : this will return the search which has
the INFO keyword from logfile.txt
✍ awk
• awk '/INFO/ {print $1 $2 $3 $6} logfile.txt : here, you can pass the
pattern ‘INFO’ and condition to print columns 1, 2, 3,
and 6 of a log file.
• awk -F',' '{print $1, $3}' fruits.txt : This will split on delimiter and
print the values of columns 1 and 3 in the output
• awk -F',' '$2 > 75 {print $1}' marks.txt : This will split on delimiter
and then the marks of students and will print their
names if marks are greater than 75.
✍ find
find : used to find files and directories in a given directory. It uses the
name, size, type, or modified time of the file to search.
• find . -name "logfile.txt" : this will find the file by name in the
current dir and its sub-directories.
• find . -name "*.txt" : this will find all the files with the
extension .txt
• find . -type d : this finds all the directories from the current
directory.
• find . -type f -size +10M : this finds all the greater than 10M
• find . -name "logfile.txt" -delete : deletes all the files which match
the filename.
✍ sed
sed [options] [pattern] [filename] : It's used to search, transform and replace
in the file/output of the command.
✍ top
✍ ps
✍ df
df : gives the disk space usage
✍ free
✍ uname
⫸ Networking
✍ ping
✍ scp
✍ useradd
✍ passwd
✍ groupadd
✍ gpasswd
• gpasswd -a username grpname : add a single user to the group
✍ deluser
✍ chmod
Permission Classes:
There are three types of permissions: read (r), write (w), and execute
(x).
chmod 772 fruits.txt : This will change the permission of the fruits.txt file
from 664 to 772.
Here in -rwxrwx-w-` the first — represents the normal file.
⫸ Miscellaneous
✍ head
head filename : display the top contents of the file, default 10 lines.
✍ tail
diff file1 file2 : it shows the difference between the two files.