Lecture 7
Lecture 7
mount command is used to mount the filesystem found on a device to big tree structure(Linux
filesystem) rooted at ‘/‘. Conversely, another command umount can be used to detach these
devices from the Tree.
Syntax: mount [-t type] device dir
umount DIRECTORY/Device
Some Important Options:
Note: The /etc/fstab file, short for "file systems table," is a system configuration file in Unix-like
operating systems, including Linux. It is used to define how various storage devices, partitions,
and network shares are mounted during the system's boot process.
Example:
1) sudo mount -l -t ext4 → Display all ext4 FS.
2) …
The file type FILE
Command to
File Type Located in using “ls -l” is command
create the File
denoted using output
PNG Image
Any data, ASCII
Regular
touch directory/Fold – Text, RAR
FIle
er archive data,
etc
Directory It is a
mkdir d Directory
File directory
Character Character
mknod /dev c
Files special
Socket socket()
/dev s Socket
Files system call
Link: https://www.geeksforgeeks.org/how-to-find-out-file-types-in-linux/
Stat
The stat is a command which gives information about the file and filesystem.
Stat command gives information such as the size of the file,
access permissions and the user ID and group ID,
birth time access time of the file.
Syntax: stat filename
Note: It also has some options…. Do it Yourself
Touch
The touch command is a standard command used in the UNIX/Linux operating system which is
used to create, change and modify the timestamps of a file.
It is used to create a file without any content. The file created using the touch command is
empty. This command can be used when the user doesn’t have data to store at the time of file
creation.
You can update the modification and access time of each file with the help of touch command.If
we are using Touch Command, but the File is already available then what will happen?
The content of the file won't be changed. But last modified date and time (i.e., timestamp) will be
updated
Cat
Cat(concatenate) command is very frequently used in Linux. It reads data from the file and gives
its content as output. It helps us to create, view, and concatenate files.
Create Files:
1) cat > newfile_name (In next lines write the content and do crtl+d for saving and exiting
the file). → This command is used to create and add content to the file.If a file doesn’t
exist it creates a new file. If the file exists then it overwrites the previous content.
2) cat >> file_name(In next lines write the content and do crtl+d for saving and exiting the
file). → This command appends the file if it is already created, else it creates the file and
adds content to it.
Concatenate Files:
3) cat file1 > file2: Creates file2 and add file1 content to file2. If file2 already exist it is
overwritten.
4) cat file1 >> file2: Creates file2 and add file1 content to file2. If file2 already exist, file1 is
appended at the end of file2.
5) cat file1.txt file2.txt file3.txt > file4.txt → Same as 3 but content consists of multiple Files.
Regular Expressions and Wildcard Characters
If we want to represent a group of strings according to a particular pattern, then we
should go for regular expressions.
By using wildcard characters, we can build regular expressions.
A wildcard character can be used as a substitute for required sequence of characters
in the
regular expression.
1) * Represents zero or more characters
2) ? Represents only one character
3) [] Range of characters
4) [abc] Either a or b or c
5) [!abc] Any character except a,b and c
6) [a-z] Any lower case alphabet symbol
7) [A-Z] Any upper case alphabet symbol
8) [a-zA-Z] Any alphabet symbol
9) [0-9] Any digit from 0 to 9
10) [a-zA-Z0-9] Any alphanumeric character
11) [!a-zA-Z0-9] Except alpha numeric character (i.e special symbol)
12) [[:lower:]] Any lower case alphabet symbol
13) [[:upper:]] Any upper case alphabet symbol
14) [[:alpha:]] Any alphabet symbol
15) [[:digit:]] Any digit from 0 to 9
16) [[:alnum:]] Any alpha numeric character
17) [![:digit:]] Any character except digit
18){} List of files with comma separator
examples
1) To list out all files present in current working directory $ ls *
2) To list out all files with some extension $ ls *.*
3) To list out all files starts with a $ ls a*
4) To list out all files starts with a and ends with t $ ls a*t
5) To list out all .java files $ ls *.java
6) To list out all files where file name contains only 2 characters and first character
should be 'a' $ ls a?
7) To list out all files where file name contains only 3 characters $ ls ???
8) To list out all files where file name contains atleast 3 characters $ ls ???*
9) To list out all files where file name starts with a or b or c $ ls [abc]*
10) To list out all files where file name should not starts with a, b and c $ ls [!abc]*
11) To list out all files starts with lower case aphabet symbol
$ ls [a-z]* OR $ls [[:lower:]]*
12) To list out all files starts with upper case aphabet symbol
$ ls [A-Z]* OR $ls [[:upper:]]*
13) To list out all files starts with digit.
$ ls [0-9]* OR $ls [[:digit:]]*
14) To list out all files where first letter should be upper case alphabet symbol, second
14) To list out all files where first letter should be upper case alphabet symbol, second
letter should be digit and third letter should be lower case alphabet symbol.
$ ls [[:upper:]][[:digit:]][[:lower:]]
15) To list out all files starts with special symbol
$ls [![:alnum:]]*
16) To list out all files with .java and .py extension
$ ls {*.java, *.py}
Note: We can use these wildcard characters with the following commands also.
cp, mv, rm
17) To copy all files starts with digit to dir1 directory.
$cp [[:digit:]]* dir1
$cp [0-9]* dir1
18) To move all files starts with alphabet symbol and with .txt extension to dir2 directory?
$mv [[:alpha:]]*.txt dir2
19) Remove all files starts with a or b or c and ends with e or t.
$rm [abc]*[et]