Search This Blog

Tuesday, 19 November 2019

Learn Linux 2

/ - indicates the root of the directory

ls -  to List the files
ls -l  to list in long format
ls -a to list the hidden files
ls -al to list files and dir in detail view
ls -R to list all  subdirectories in directiories

create a file in CLI and add content  ---- cat > filename
display content of file ------ Cat filename
remove a file -----   rm filename

create directry ---------- mkdir  filename
remove dirtry ------------ rmdir filename

move file or rename ------mv file1  file2

sudo  --- allows user to run with root permissions

man or help  ----- give information of command

history ---- help to view the previous commands executed

clear ---- clear the terminal

pr -    command is used  format the file content and print
pr -x    filename


cat - to read a file


Permission:

- indicates the file (-rwx)
d indicates the directory(drwx)


rwx- read,write,execute  for file
Users(Owner,Group,Others) for file

chmod - to give permission to file or directories
chown  - used to chnage owner or group name


Output redirection:

ls -l > txt

redirecting the output to file txt


PIPE:
Helps you to use two or more commands at same time

cat filename | less or Pg or more  ----- display  first page and we need to scroll down using arrow

FIND:
find . name 'filename'
. current directory
to search for file

GREP:

to search for string in file
cat requirements.txt | grep six
six==1.11.0

grep -c   --- display count of matching
grep -n  ---- display  matching line with number
grep  -i    --- display upper and lower case matching
grep -v    ---- display all lines donot macth string


Linux has a lot of filter commands like awk, grep, sed, spell, and wc

Regex:

.   replace any  character
^ start with character macthes
$ end with character macthes
* matches any character o or more
\ matches special chracter
? matches any single chracter

\+ matches  one or more  preceding character
\? matches zero or more preceding chracter

examples:

grep -E a\+t
grep -E a\?t

Range:
examples

echo {0..10}
echo {a..z}
echo test{0..8}



SORT:

sorting content of file alphabetically,numerically,case sensitive

sort   filename
-r    reverse sorting
-n   sort numerically
-f    case sentive

No comments:

Post a Comment

REST API

  API  is an application programming interface. It is a set of rules that allow programs to talk to each other. The developer creates the AP...