DEV Community

Cover image for Linux Commands
Ranjit Odedra
Ranjit Odedra

Posted on

Linux Commands

mkdir → to make a new directory

ls → to print list of all dirctories and files

clear → to clear terminal

whoami → to display the current user

pwd → display the current working directory

cd → to change directory

touch filename.txt → create a empty text file

touch file{1..5}.txt → create 5 empty file

cat > filename.txt → add content to file from terminal

cat filename.txt → print content of file

cat file{1..2}.txt → print content of file1 to file2

cat >> file1.txt → to update content of file

cp file1.txt file2.txt → copy content of file1 into file2

mv file3.txt f3.txt → rename file3 as f3

wc -l file1.txt → print count of lines in file

wc -w file1.txt → print count of words in file

wc -m file1.txt → print count of character in file

cmp file4.txt file5.txt → compare two file byte by byte and tell its identical or not

comm file4.txt file5.txt → gives what is comman in file4 and file5 (also used to find unique)

diff file4.txt file5.txt → give difference between file4 and file5

sort f{1..2}.txt → sort content of f1.txt and f2.txt (alphabetically)

cat f1.txt f2.txt > f3.txt → merge two files f1.txt and f2.txt and copy in to f3.txt

sort f3.txt | uniq -u → remove all dublicates from f3.txt and print (doesn’t affect the original file).

tr a-z A-Z < f1.txt → translate lower case to upper case (doesn’t affect the original file).

sed ‘s/[0-9]*//g’ < f1.txt → remove numeric values from file.

head f3.txt → print first 10 lines from file

tail f3.txt → print last 10 lines from file

more f3.txt → print all things *

less f3.txt → print all things *

grep -w linux < file9.txt → it gives all lines containing linux word (grep linux file9.txt)

grep -n linux < file9.txt → it gives line number with line containing linux word

grep -a --count linux < file9.txt → it gives count of line containing linux word

grep ‘+linux*’ file9.txt → gives the lines which starts from linux word

grep ‘os$’ file9.txt → gives lines which ends with os word

ls -l → gives what permissions files have

ls -l filename→ gives what permissions files have

ls -ld → gives directory permissions

history > workdone.txt → history give all the commands that we just write we can store it text file

w → gives info about all users

Permissions

rwx     rwx     rwx
user    group   other
Enter fullscreen mode Exit fullscreen mode

Note that “r” is for read, “w” is for write, and “x” is for execute

Untitled

chmod ugo+rwx foldername → to give read, write, and execute to everyone.

chmod a=r foldername → to give only read permission for everyone.

Untitled

  1. The first character will almost always be either a ‘-‘, which means it’s a file, or a ‘d’, which means it’s a directory.
  2. The next nine characters (rw-r–r–) show the security;
  3. The next column shows the owner of the file. In this case it is me, my userID is “aditya314”.
  4. The next column shows the group owner of the file. In my case I want to give the “aditya314” group of people special access to these files.
  5. The next column shows the size of the file in bytes.
  6. The next column shows the date and time the file was last modified.
  7. And, of course, the final column gives the filename.

chmod 755 file.txt → to change permissions of file

chmod 555 ce → change permission of directory

new permission will be -rwxr-xr-x

id → gives information about current user and groups and other info

$HOME → gives path of home.

$PATH → also give path

sudo su → become root user

head -5 file.txt → print first five lines

tail -2 file.txt → print last two lines

rm file.txt → remove file

rm -r directory_name → remove dirctory

sudo adduser username → adds a new user

sudo addgroup g1 → adds new group

sudo groupadd -g 10000 groupname → create group

cat /etc/group → display all the groups

sudo usermod -aG groupname username → add user to a group

sudo chown username filename → to change username

sudo chown username:groupname filename`→ change group name

sudo chgrp groupname filename → change groupname

sudo chgr groupname directoryname → change groupname

umask → display current value of shells mask

umask 531 → set umask

top → display all processes

ps → give all process associated with current user

ps aux → list down all the processes associated with their terminal and states

ps l

ps lx

kill -l → display all names and number of available signal

Top comments (0)