Managing the Files and Folders in Linux (PART I)

How to manage files and folders in Linux from the terminal?

The touch command in Linux is used to change file access and modification times. You can get the complete details of the touch command by running any one of the following commands from the terminal. man touch or touch --help

NAME
touch – change file access and modification timesSYNOPSIS
touch [-A [-][[hh]mm]SS] [-achm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] [-d YYYY-MM-DDThh:mm:SS[.frac][tz]] file ...
The output of the man touch command in Linux
Create a new file using touch in Linux
touch album{1..4}_song{1..5}.mp4
Create multiple files at once using the touch command in Linux
ls -l album* | cut -d_ -f1 | sort | uniq
Piping multiple commands in Linux to filter the file names.
rm album{1..4}_song{1..5}.mp4
remove multiple files at once using the rm command in Linux
A detailed video on the touch command in Linux
The output of man mkdir command in Linux
mkdir -p  retail/orders/2022/08/27
-p             Create intermediate directories as required.  If this option is not specified, the full path prefix of each operand must already exist.  On the other hand, with this option specified, no error will be reported if a directory given as an operand already exists.  Intermediate directories are created with permission bits of “rwxrwxrwx” (0777) as modified by the current umask, plus write and search permission for the owner.
Create a hierarchy of directories using mkdir command in Linux
mkdir -p album{1..4}/artist{1..3}
Create multiple folders and files at once using mkdir command
rm -rf album*
How to use mkdir command to create multiple hierarchies of folders and files.
The awk is pattern-directed scanning and processing language. Awk scans each input file for lines that match any of a set of patterns specified literally in prog or in one or more files specified as -f progfile. With each pattern, there can be an associated action that will be performed when a line of a file matches the pattern. Each line is matched against the pattern portion of every pattern-action statement; the associated action is performed for each matched pattern.
man awk command to get the details of awk in Linux terminal.
Clone the above repository for the data to practice.
awk -F"," '{ print $4}' part-00000 | sort | uniqThe -F fs option defines the input field separator to be the regular expression fs.
get the data from a specific column using the awk command from CSV file.
awk -F"," '{ print "Order status is " $4}' part-00000 | sort | uniq
Print the output in the requested format using the awk command.
cat part-00000 | awk -F"," '{ print "Order status is " $4}' | sort | uniq
pipe the output of cat command to awk command.
A detailed explanation of the awk command in Linux.
Create multiple files and a folder for hands-on practice.
Detailed overview of the copy command in Linux
remove multiple files at once using the rm command in Linux.
A detailed explanation of copying files using the cp command in Linux.
Get the files in the present working directory using ls -l
ls -1 | awk -F"_" '{ print $1}' | sort | uniq
piping ls command to awk command to get the file names in Linux
ls -1 | awk -F"_" '{ print "/tmp/demo/albums/" $1 }' | sort | uniq
Print the files in the required format using the print inside awk command.
ls -1 | awk -F"_" '{ print "mkdir -p /tmp/demo/albums/" $1 }' | sort | uniq | bash
Create multiple folders at once using the awk command with mkdir in Linux
A detailed explanation of how to use the awk command with mkdir command to create folders.
cp album1_song1.mp4 /tmp/demo/albums/album1
ls -1 | awk -F"_" '{ print "cp " $0 " " $1 }'
Generate the pattern of cp commands by using the awk command
ls -1 | awk -F"_" '{print "cp " $0 " /tmp/demo/albums/" $1 "/" $2}'
Generate the complete pattern of cp commands using the awk command to copy multiple files at once
ls -1 | awk -F"_" '{print "cp " $0 " /tmp/demo/albums/" $1 "/" $2}' | bash
Validate whether files were copied successfully or not by using the find command
A detailed explanation of using the awk command to automate the bulk file copy process.
Albums we created in the previous sections using the awk command in Linux
cp -r /tmp/demo/albums .
Albums folder copied recursively to the current directory using cp command in Linux
Check all the files copied from source to destination in time.
A detailed explanation of how to use copy command recursively in Linux.
cp -rp [source][destination]-p    Cause cp to preserve the following attributes of each source file in the copy: modification time, access time, file flags, file mode, user ID, and group ID, as allowed by permissions.
A detailed explanation of copying files using cp while preserving properties in Linux.
man mv command to get the details of the mv command in Linux
Move the file from source to destination using mkdir
renaming the file using the mv command in Linux
mv album2_*.mp4 /tmp/albums
You can move multiple files at once using a pattern with the mv command in Linux
A detailed explanation of how to use mv command in Linux.
ls -1 | awk -F"_" '{print "mkdir -p /tmp/albums/" $1 }' | sort | uniq | bash
Create multiple folders using the awk command
ls -1 | awk -F"_" '{print "mv " $0 " /tmp/albums/" $1 "/" $2 }' | sort | uniq | bash
How to move multiple files at once using awk command in Linux?
A detailed explanation of using the awk command in Linux to automate the file move.