[email protected]:~$ ls /home/user1/Music
) or relative paths (ex: [email protected]:~$ ls Music/
) with ls. -1
prints outs each result in 1 line:-l
for long listing format : -a
option:stat
command.(we use ubuntu 16.04 here)-c
option tells that if the file does not exist, do not create it:-a
: change the access time only-d
: update the access and modification times-m
: change the modification time only-r
: use the access and modification times of other file as reference.-t
: creates a file using a specified timetouch -t YYMMDDHHMM fileName
touch -a fileName
touch -m fileName
touch -c -t YYDDHHMM filename
touch -c -d fileName
touch -r refrence_file_name file_name
-p
enables the command to create parent directories as necessary. If the directories exist, no error is specified:-v
option, it prints a message for each created directory.cp
command is a command-line utility for copying files and directories. [Copies of files are independent of the original file( unlike the mv
command) ].The basic syntax of the cp command is:cp can take 1 or more sources(s) but just one destination.
-b
flag may be used to create a back up of the file. This copies the file into place and writes a backup file.-S
option. try cp -S .file2bak file1 file2
-R
option to perform a recursive copy.cp -R ~/test-space ~/files-backup
-R
flag. This will recursively copy a folder and create a copy.man cp
command for more information.mv
is used to move or rename one or more files or directories. In general, the names we can use follow the same rules as for copying with cp; [If you are moving a file on the same file system, the inode wont change]. mv -t dirA dir3
command as well. -t, --target-directory
Move all sources into the directory destination.
cp vs mv :Normally, the cp command will copy a file over an existing copy, if the existing file is writable. On the other hand, the mv will not move or rename a file if the target exists. We can overcome this using the-f
switch.
rm
stands for remove here. rm
removes files or directories.rm -- -file.txt
Or, we can delete it by referring to it with a pathname : rm /home/hope/-file.txt
rm
does not remove directories.rm -d
lets us to remove a directory without specifying -r/-R/--recursive, provided that the directory is empty. In other words, rm -d is equivalent to using rmdir.rmdir
only if it is empty as there is no option to force removal.-p
option to remove parents as well. Let try it:rmdir
is instructed to remove a non-empty directory, it reports an error. With --ignore-fail-on-non-empty
option suppresses those error messages.-r
(or -R or --recursive) option to cause the rm command to remove both files and directories:?
is used to match any single character. We can use ‘?’ for multiple times for matching multiple characters.*
is used to match zero or more characters. If we have less information to search any file or information then we can use ‘*’ in globbing pattern.[ ]
is used to match the character from the range. Some of the mostly used range declarations are mentioned below:[A-Z]
: All uppercase alphabets[a-z]
: All lowercase alphabets[a-zA-Z0-9]
: All uppercase alphabets, lowercase alphabet and digitsThe-
character between two others represents a range that includes the two other characters and all characters between them in the collating sequence.
!
character means NOT so it matches any character except the remaining characters.{ }
can be used to match filenames with more than one globbing patterns. Each pattern is separated by ‘,’ in curly bracket without any space.rm {*.doc,*.docx}
: delete all files whose extensions are ‘doc’ or ‘docx’.\
is used as an "escape" character, we have used it to protect a subsequent special character. example: "\\” searches for a backslashWe can disable globbing usingset -f
command.
starting/path
attribute will define the top level directory where find begins filtering.options
attribute will control the behavior and optimization method of the find process.expression
attribute controls the tests that search the directory hierarchy to produce output.-name
option used for searching for files based on their name. -i
makes it case insensitive. In the first example above, we found both files and a directory (/etc). find . -name ".*"
find . -name file1 -or -name file9
-type f
will search for a regular file-type d
will search for a directory-type l
will search for a symbolic link-size +/- [b] [c] [w] [k] [M} [G]
find . -size 0b
or find . -empty
.-daystart
option to -mtime
or -atime
means that we want to consider days as calendar days, starting at midnight. So to list the regular files in your home directory that were modified yesterday we can use find ~/ -daystart -type f -mtime 1
.We can also find files by owner and permissions and use filter result by depth (will be discussed in later sections"104-7")
{}
is used as a placeholder for the files that find matches. The “\;” is used so that find knows where the command ends.-b, –brief
: This is used to display just file type in brief mode.-z
: Try to look inside compressed files.-i
option To view mime type of file.Zip
is one of the most popular archive file format out there. With zip, you can compress multiple files into one file. This not only saves disk space, it also saves network bandwidth. This is why you’ll encounter zip files almost all the time.-r
option with the zip command and it will recursively zips the files in a directory. This option helps you to zip all the files present in the specified directory: