32.managing Files
32.managing Files
WITH
FILES & DIRECTORIES
LINUX & SCRIPTING
Mr. RAM
LS COMMAND:
It lists directory contents of files and directories. It provides valuable
information about files, directories, and their attributes.
To List Files:
$ls
To List reverse order:
$ls -r
Long format that displays detailed information about files and
directories:
$ls -l
To list specific file details:
$ls -l file-name
Represent all files Include hidden files and directories:
$ls -a [ File start with “.” ]
List files and directories recursively, including subdirectories:
$ls -R
List inode which displays the index number of each file and directory:
$ls -i
List directories themselves, rather than their contents:
$ls -d
Sort files and directories by their sizes, listing the largest ones first:
$ls -s or $ls -S
Print file sizes in human-readable format (e.g., 1K, 234M, 2G).
$ls -lh
Sort files and directories by their last modification time, displaying the
most recently modified ones first:
$ls -t $ls -lhtr
LINUX & SCRIPTING
Mr. RAM
PATH:
A path describes a location to a file in a file system of an OS.
A path to a file is a combination of / and alpha numeric characters.
There are two types.
ABSOLUTE PATH:
Path is defined as the specifying the location of a file or directory from the
root directory (/).
Example: $ls /usr/share/doc
$ls /home/raju
RELATIVE PATH:
Absolute paths are useful, but they're not always efficient.
It is defined as path related to the present working directory (pwd).
Example: $cd /var/log
$ls
PWD COMMAND:
Prints the current working directory.
The pwd command is your Linux system's compass, in that it tells you where
you are.
To print working directory
$pwd
STAT COMMAND:
It displays file or file system status.
To check file statistics:
$stat myfile
$stat -f myfile
LINUX & SCRIPTING
Mr. RAM
To Print a output:
$cat <filename>
(or)
$cat < filename
TOUCH COMMAND:
The touch command is another one that serves a dual purpose.
It is used to create a new empty (zero byte) file.
Touch can create, change, and modify file timestamps.
MKDIR COMMAND:
It is used to create a new directory.
SYNTAX: $mkdir [options] <Dir name>
$mkdir cloud
DIRECTORY NAVIGATION:
CD COMMAND:
It is a change directory.
Changing directories is easy as long as you know where you are (your
current directory) and how that relates to where you want to go.
SYNTAX: $cd <Dir name>
$cd cloud
$touch aws
$ls
LINUX & SCRIPTING
Mr. RAM
To change directory to the one above your current directory, use the
double period (dot) argument:
$cd ..
$pwd
To get Users home directory:
$cd ~ (or) $cd
NOTE: SHORTCUTS:
Single dot, or . : Represents current location.
Double dot, or .. : To change one above directory
Double dot, or ../.. : To change two above directory
Hyphen or - : Previous Directory
Tilde, or ~ : Users home directory
RM COMMAND:
The rm command removes (deletes) files and directories.
CP COMMAND:
cp command is used to copies files and directories.
There's no great secret to its usage and you simply issue the copy (cp)
command, the file or directory source, and the destination.
MV COMMAND:
The mv command moves files and directories from one directory to another
or renames a file or directory.
When you use the mv command to rename a file or directory, the Target
Directory parameter can specify either a new file name or a new directory
path name.
SEMICOLON (;):
A command line can consist of multiple commands. Each command is
separated by a semicolon.
The exit status is that of the last command in the chain of commands.
It is a command independent; meaning is not depending on first command.