Code Scrappers


Files & Directories - Unix Commands


: editor command -

~ It creates a new file and opens it.

saarthak@DESKTOP-N01EJET:~$ editor sample.txt
            



: ls command -

~ It displays all the file present in the current directory.

saarthak@DESKTOP-N01EJET:~$ ls
hello.c   kruskals.c   sample.txt   home.txt    base.txt
          



: cp command -

~ It copies content of one file to another.

saarthak@DESKTOP-N01EJET:~$ cp sample.txt home.txt
            



: mv command -

~ It moves content of one file to another.

saarthak@DESKTOP-N01EJET:~$ mv sample.txt home.txt
              



: rm command -

~ It removes the file.

saarthak@DESKTOP-N01EJET:~$ rm sample.txt
            



: ls -l command -

~ ls –l provides attributes like Permissions, Links, Owner, Group owner, Size, Date, File name .

saarthak@DESKTOP-N01EJET:~$ ls -l
-rw-rw-rw- 1 saarthak saarthak 7 Jul 23 13:24 base.txt
-rw-rw-rw- 1 saarthak saarthak 7 Jul 23 13:22 hello.c
-rw-rw-rw- 1 saarthak saarthak 8 Jul 23 13:23 home.txt
-rw-rw-rw- 1 saarthak saarthak 7 Jul 23 13:22 kruskal.c
-rw-rw-rw- 1 saarthak saarthak 8 Jul 23 13:22 sample.txt
    



: chmod command -

~ It lets you change the read, write, and execute permissions on your files.

u - owner, g - group owner, o - others, a - for all.

r - read permission, w - write permission, x - execute permission

saarthak@DESKTOP-N01EJET:~/learn$ chmod u+x base.txt
saarthak@DESKTOP-N01EJET:~/learn$ chmod g+x hello.c
saarthak@DESKTOP-N01EJET:~/learn$ chmod o-w home.txt
saarthak@DESKTOP-N01EJET:~/learn$ chmod a-r kruskal.c
saarthak@DESKTOP-N01EJET:~/learn$ ls -l
total 0
-rwxrw-rw- 1 saarthak saarthak 7 Jul 23 13:24 base.txt
-rw-rwxrw- 1 saarthak saarthak 7 Jul 23 13:22 hello.c
-rw-rw-r-- 1 saarthak saarthak 8 Jul 23 13:23 home.txt
--w--w--w- 1 saarthak saarthak 7 Jul 23 13:22 kruskal.c
-rw-rw-rw- 1 saarthak saarthak 8 Jul 23 13:22 sample.txt
            



: chmod command (using numbers) -

~ It lets you change the read, write, and execute permissions on your files.

Read permission - 4, Write permission - 2, execute permission - 1

saarthak@DESKTOP-N01EJET:~/learn$ chmod 766 base.txt
saarthak@DESKTOP-N01EJET:~/learn$ chmod 676 hello.c
saarthak@DESKTOP-N01EJET:~/learn$ chmod 664 home.txt
saarthak@DESKTOP-N01EJET:~/learn$ chmod 222 kruskal.c
saarthak@DESKTOP-N01EJET:~/learn$ ls -l
total 0
-rwxrw-rw- 1 saarthak saarthak 7 Jul 23 13:24 base.txt
-rw-rwxrw- 1 saarthak saarthak 7 Jul 23 13:22 hello.c
-rw-rw-r-- 1 saarthak saarthak 8 Jul 23 13:23 home.txt
--w--w--w- 1 saarthak saarthak 7 Jul 23 13:22 kruskal.c
-rw-rw-rw- 1 saarthak saarthak 8 Jul 23 13:22 sample.txt
            



: chown command -

~ It changes the owner of the file.

saarthak@DESKTOP-N01EJET:~$ ls -l
-rw-rw-rw- 1 saarthak saarthak 7 Jul 23 13:24 base.txt

saarthak@DESKTOP-N01EJET:~$ chown shweta base.txt
saarthak@DESKTOP-N01EJET:~$ ls -l
-rw-rw-rw- 1 shweta saarthak 7 Jul 23 13:24 base.txt
            



: chgrp command -

~ It changes the group owner of the file.

saarthak@DESKTOP-N01EJET:~$ ls -l
-rw-rw-rw- 1 shweta saarthak 7 Jul 23 13:24 base.txt

saarthak@DESKTOP-N01EJET:~$ chgrp prateek base.txt
saarthak@DESKTOP-N01EJET:~$ ls -l
-rw-rw-rw- 1 shweta prateek 7 Jul 23 13:24 base.txt
            



: mkdir command -

~ It makes new directory.

saarthak@DESKTOP-N01EJET:~$ mkdir travel
            



: cd command -

~ It is used to enter into a directory.

saarthak@DESKTOP-N01EJET:~$ cd travel
saarthak@DESKTOP-N01EJET:~/travel$
            



: cd .. command -

~ It is used to exit from a directory.

saarthak@DESKTOP-N01EJET:~/travel$ cd ..
saarthak@DESKTOP-N01EJET:~$