Cmds 1
Cmds 1
df
2. ls
3. ping
https://www.guru99.com/linux-
redirection.htmlListing files (ls)
If you want to see the list of files on your UNIX or Linux system, use the 'ls' command.
Note:
You can use 'ls -R' to shows all the files not only in directories but also subdirectories
NOTE: The command is case-sensitive. If you enter, "ls - r" you will get an error.
'ls -al' gives detailed information of the files. The command provides information in a columnar
format. The columns contain the following information:
Hidden items in UNIX/Linux begin with - at the start, of the file or directory.
Any Directory/file starting with a '.' will not be seen unless you request for it. To view hidden
files, use the command.
ls -a
cat filename
As soon as you insert this command and hit enter, the files are concatenated, but you do not see a
result. This is because Bash Shell (Terminal) is silent type. It will never give you a
confirmation message like "OK" or "Command Successfully Executed". It will only show a
message when something goes wrong or when an error has occurred.
cat sample
Note: Only text files can be displayed and combined using this command.
Deleting Files
The 'rm' command removes files from the system without confirmation.
rm filename
mv filename new_file_location
mv sample2 /home/guru99/Documents
mv command needs super user permission. Currently, we are executing the command as a
standard user. Hence we get the above error. To overcome the error use command.
sudo command_you_want_to_execute
Sudo program allows regular users to run programs with the security privileges of the superuser
or root.
Sudo command will ask for password authentication. Though, you do not need to know the root
password. You can supply your own password. After authentication, the system will invoke the
requested command.
Sudo maintains a log of each command run. System administrators can trackback the person
responsible for undesirable changes in the system.
mv filename newfilename
NOTE: By default, the password you entered for sudo is retained for 15 minutes per terminal.
This eliminates the need of entering the password time and again.
You only need root/sudo privileges, only if the command involves files or directories not owned
by the user or group running the commands
Directory Manipulations
Creating Directories
Directories can be created on a Linux operating system using the following command
mkdir directoryname
This command will create a subdirectory in your present working directory, which is usually
your "Home Directory".
For example,
mkdir mydirectory
If you want to create a directory in a different location other than 'Home directory', you could use
the following command -
mkdir
For example:
mkdir /tmp/MUSIC
Removing Directories
To remove a directory, use the command -
rmdir directoryname
Example
rmdir mydirectory
Tip: Ensure that there is no file / sub-directory under the directory that you want to delete. Delete
the files/sub-directory first before deleting the parent directory.
Renaming Directory
The 'mv' (move) command (covered earlier) can also be used for renaming directories. Use the
below-given format:
mv directoryname newdirectoryname
To get help on any command that you do not understand, you can type
man
The terminal would open the manual page for that command.
For an example, if we type man man and hit enter; terminal would give us information on man
command
We can use the 'chmod' command which stands for 'change mode'. Using the command, we can
set permissions (read, write, execute) on a file/directory for the owner, group and the world.
Syntax:
1. Absolute mode
2. Symbolic mode
Absolute(Numeric) Mode
In this mode, file permissions are not represented as characters but a three-digit octal
number.
The table below gives numbers for all for permissions types.
0 No Permission ---
1 Execute --x
2 Write -w-
4 Read r--
In the above-given terminal window, we have changed the permissions of the file 'sample to
'764'.
This is how you can change the permissions on file by assigning an absolute number.
Symbolic Mode
In the Absolute mode, you change permissions for all 3 owners. In the symbolic mode, you can
modify permissions of a specific owner. It makes use of mathematical symbols to modify the file
permissions.
Operator Description
User Denotations
u user/owner
g group
o other
a all
We will not be using permissions in numbers like 755 but characters like rwx. Let's look into an
example