Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 10, 2021 05:21 pm GMT

Let's Learn more about Linux/Unix Commands

Hi there!, Lets learn few more about Linux/Unix commands.

1.chmod:
chmod stands for change mode. It's used to change access of a file. Linux has total 27 kinds of file permissions. listing few of them.

Please don't apply this command outside of your home directory. If you will change access on System Directory with sudo command, you may have to reinstall your OS again.

Syntax:

chmod [references][operator][modes] file...
Enter fullscreen mode Exit fullscreen mode

we can also say that, this syntax as who(user) as reference,what(what permission) as operator, mode as which(which permission).

[reference]: It represents that whom to give permission.

ReferenceClassDescription
uuserFiles owner
ggroupUsers who are Members of the files group
oothersUser who are neither the files owner nor members of the files group
aallAll three of the above, same as ugo

[operator]: It represents what permission we are making. Are we adding or removing or setting new permission?

OperatorDescription
+add the permission.
-remove the permission.
=set the permission and wipe out previous permissions.

[modes]: It represents which permission to be granted.

ModesNamesDescription
rreadread permission to a file or a directory
wwritewrite permission to a file or a directory
xexecuteexecute permission to a file

Example:

Alt Text

Please see left sided values in above example ( like drwxrwxr-x or -rw-r--r-- etc), we called these symbolic value. These sections divided into 4 parts- File types, owner, group and other.

Let's make this example simple to see what permission given to which file. I am taking few examples from the above screenshot.

File typesowner permissiongroup permissionother permissionhard linkfile/directory name
drwxr-xr-x2Desktop
-rw-r--r--1get-docker.sh
drwxrwxr-x2payal
-r-xr--r--1test.sh

File type: It has two types
d: for directory and
- : for regular file.

owner permission: we can see different owner permissions.
rwx: For Desktop & payal directories, the directory's owner can create files within it, can list its contents and descend into it.

rw-: For get-docker.sh file, the file owner can read from the file and write to the file but can't execute the file as "-" ( which means no permission) provided in execute position.
r-x: For test.sh file, the file owner can read from the file and execute the file.

group permission: we can see different group permission.
r-x: For Desktop directory, the member of directory's group can read and descend into it.
r--: For get-docker.sh & test.sh files, the members of the file's group can read from the file but can't write and execute as "-" provided for both places.
rwx: For payal directory, the members of the directory's group can read, write and descend into it.

other permission:
r-x: For Desktop and payal directories, the other users can read and descend into it.
r--: For get-docker.sh & test.sh files, other users can only read from the file .

File Permission can also be given through octa values:
Let's take an example from above example for Desktop directory.

 rwx  r-x  r-x  u    g    o
Enter fullscreen mode Exit fullscreen mode
PermissionBinaryOctalUserGroupOther
r1004444
w0102200
x0011111
total number766

Now we can change the permission using below ways:
1.

chmod u+rwx g+rx o+rx <file>
Enter fullscreen mode Exit fullscreen mode

2.

chmod 766 <file>
Enter fullscreen mode Exit fullscreen mode

So both of the commands will give same permission to the file.

2. cal:
cal stands for calendar i.e. use to see calendar in terminal.

Syntax:

cal [-jy] [[month] year]
Enter fullscreen mode Exit fullscreen mode

-j: Show julian dates (days one-based, numbered from January 1)
-y: Show calendar from the current year

Example:

Alt Text

Example:

Alt Text

3. grep:
grep stands for Global Regular Expression Print. It is used to search for a particular pattern of a character and print all the contain that pattern.

Syntax:

 grep [OPTIONs]... PATTERN [FILE]..
Enter fullscreen mode Exit fullscreen mode

We can use grep command in so many ways. Given few examples.

grep [options] Pattern [file]: Search the file with Options. There are so many options, I provided few as examples.

  • grep -c "string-to-search" [FILE] : It find the number of lines that matches the pattern.

Example:

Alt Text

  • grep -i "string-to-search" [FILE] : It search string case insensitively.

    Example:
    Alt Text

NOTE:
Do grep --help to know more about Options.

grep "string-to-search" [file] : Search the word in a single file.

Example:

Alt Text

grep "string-to-search" [file1] [file2] [file3] [file4]: Search the word in a multiple files.

Example:

Alt Text

[some-commands] | grep "string-to-search" : Put some command and search.

Example:

Alt Text

cat [file] | grep "string-to-search" : While concatenate the file and search particular.

Example:

Alt Text

4. zip:
zip command used for compressed files with .zip extension. We can zip files and directories in linux/unix. zip files use in Linux for many reasons. Even we can share the zip file with Window users instead of .tar extension as it won't be compatible.

Syntax:

zip [OPTIONS] filename.zip [list of files]
Enter fullscreen mode Exit fullscreen mode
  • zip filename.zip [file1] [file2] : Creating zip with files:

Example:

Alt Text

  • zip filename.zip [list of files] [list of directories] : Creating zip with files and directories.

Example:

Alt Text

  • zip -e filename.zip [list of files] : Creating password protecting zip.

Example:

Alt Text

5. unzip:
unzip command used for unzipping the zip files.

Syntax:

unzip [OPTIONS] [filename.zip]
Enter fullscreen mode Exit fullscreen mode
  • unzip [filename.zip] : Unzipping the above created zip file combined with files and directories.

Example:

Alt Text

  • unzip -P [password] [filename.zip] : Unzipping password protected zip file.

Example:

Alt Text

NOTE: Providing password in command line is not secure and it should be avoided. We can overcome this situation just providing the below command without providing the password. So, if the zip file is encrypted then unzip command will prompt with window to enter the password.

unzip [filename.zip] 
Enter fullscreen mode Exit fullscreen mode

Example:

Alt Text


Original Link: https://dev.to/payalsasmal/let-s-learn-more-about-linux-unix-commands-5aai

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To