-
Notifications
You must be signed in to change notification settings - Fork 0
Home
What is shell script?
A file that contains a series of commands.
Anything you can do on the command line can be automated by writing a shell script.
In Linux everything is a File. Everything is a file. 📁
We can use type
command to check whether the command or is what type shell builtin or ...
example:
type ps
To check which shell type currently using, we could use the SHELL
variable
command
Execute a simple command or display information about commands.
Its just used to execute the command and also by using the -v
flag we could see the some information about that program.
To see all available shell variables and much more.
man bash
Here are some of the shell variables
printenv
- print all or part of environment
date
- print or set the system date and time
To print the date in our required format date +YOUR_FORMAT
See the available formats in the man page
What's the suitable location to place the script that is shared with some users.
/usr/local/bin
find
- search for files in a directory hierarchy recursively
find <from_path> -type <FILE_TYPE> -name <NAME_OF_FILE>
-type File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If
you want to search for symbolic links when -L is in effect, use -xtype.
s socket
D door (Solaris)
To search for more than one type at once, you can supply the combined list of type letters separated by a comma `,' (GNU extension).
-name
name of the file or dir, supports the wildcard masks.
tar
- an archiving utility
Usage:
To create tar file from the files or folders
tar -c [-f ARCHIVE] [OPTIONS] [FILE...]
-c is to create. -f is used to mentioned the tar file name, you can specify the additional options like -v for the verbose, finally files name and/or folders name
Example:
If you have the folder to archive then instead of files array give the folder name
-t is used to list the contents of the tar file
-x is used to Extract files from an archive.
-z is used to to compress the file. (like gzip)
To extract the compressed tar using the tar command
Note: When you are working with the tar compressed file always use the -z options.
tar
command,
-
-f
to specify the archive file name -
-c
to create -
-t
to list the contents of the archive file -
-x
to extract the archive file -
-z
while working with the compressed archive -
-v
is for verbosity
gzip
compress files
Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz
gzip filename
```gunzip`` expand files
echo
display a line of text
-e enable interpretation of backslash escapes
du
- estimate file space usage
-h
human readable
ln
creating links between files
By default, the ln command creates hard links. To create a symbolic link, use the -s
(--symbolic) option.
The ln
command syntax for creating symbolic links is as follows:
ln -s [OPTIONS] FILE LINK
Source file (My script)
Linking the file to form a Global cmd.
Output of the ls
shows the link that we created.