iWhiver
6/5/2019 - 8:04 AM

Linux files and Directories

*                   Matches any characters
?                   Matches any single character
[characters]        Matches any character that is a member of the set characters
[!characters]       Matches any character that is not a member of the set characters
[[:class:]]         Matches any character that is a member of the specified class
====
[:alnum:]           Matches any alphanumeric character
[:alpha:]           Matches any alphabetic character
[:digit:]           Matches any numeral
[:lower:]           Matches any lowercase letter
[:upper:]           Matches any uppercase letter

examples =>

*                           All files
g*                          Any file beginning with g
b*.txt                      Any file beginning with b followed by any characters and anding with .txt
Data???                     Any file beginning with Data followed by exactly three characters
[abc]*                      Any file beginning with either an a, a b, or a c
BACKUP.[0-9][0-9][0-9]      Any file beginning with BACKUP. followed by exactly three numerals
[[:upper:]]*                Any file beginning with an uppercase letter
[![:digit:]]*               Any file not beginning with a numeral
*[[:lower:]123]             Any file ending with a lowercase letter or the numerals 1, 2, or 3
cp file1 file2            Copy file1 to file2. If file2 exists, it is overwritten with the contents
of file1. If file2 does not exist, it is created.

cp -i file1 file2         Same as previous command, except that if file2 exists, the user
is prompted before it is overwritten.

cp file1 file2 dir1       Copy file1 and file2 into directory dir1. The directory dir1
must already exist.

cp dir1/* dir2            Using a wildcard, copy all the files in dir1 into dir2. The directory
dir2 must already exist.

cp -r dir1 dir2           Copy the contents of directory dir1 to directory dir2. If directory
dir2 does not exist, it is created and, after the copy, will contain
the same contents as directory dir1. If directory dir2 does exist,
then directory dir1 (and its contents) will be copied into dir2.

cp *.html destination     Copy all files that endes with .thml
mkdir dir1 - one dir

mkdir dir1 dir2 dir3 - three dirs
mv file1 file2            Move file1 to file2. If file2 exists, it is overwritten with the contents
of file1. If file2 does not exist, it is created. In either case,
file1 ceases to exist.

mv -i file1 file2         Same as the previous command, except that if file2 exists, the
user is prompted before it is overwritten.

mv file1 file2 dir1       Move file1 and file2 into directory dir1. The directory dir1
must already exist.

mv dir1 dir2              If directory dir2 does not exist, create directory dir2 and move
the contents of directory dir1 into dir2 and delete directory dir1.
If directory dir2 does exist, move directory dir1 (and its contents)
into directory dir2.
rm file1            Delete file1 silently.

rm -i file1 file2 file3 file4       Delete four files and user is
prompted for confirmation before the deletion is performed.

rm -r file1 dir1    Delete file1 and dir1 and its contents.

rm -rf file1 dir1   Same as the previous command, except that if

rm -rf dir dir2 dir3