Basic Linux
Basic Linux
File Management becomes easy if you know the right basic command in Linux.
Sometimes, commands are also referred as “programs” since whenever you run a
command, it’s the corresponding program code, written for the command, which is
being executed.
Let’s learn the must know Linux basic commands with examples:
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: These Linux basics commands are 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:
Any Directory/file starting with a ‘.’ will not be seen unless you request for it. To view
hidden files, use the command.
ls -a
Creating & Viewing Files
The ‘cat’ server command is used to display text files. It can also be used for copying,
combining and creating new text files. Let’s see how it works.
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. Shell
Commands 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.
Note: Only text files can be displayed and combined using this command.
Deleting Files
The ‘rm’ command removes files from the system without confirmation.
mv sample2 /home/guru99/Documents
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.
guru99@VirtualBox:~$ sudo mv sample2 /home/quru99/Documents
[sudo] password for guru99: ****
guru99@VirtualBox:~$
For renaming file:
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
Directory Manipulation in Linux/Unix
Enough with File manipulations! Let’s learn some directory manipulation Linux
commands with examples and syntax.
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
will create a directory ‘Music’ under ‘/tmp’ directory
You can also create more than one directory at a time.
Removing Directories
To remove a directory, use the command –
rmdir directoryname
Example
rmdir mydirectory
will delete the directory 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
Let us try it:
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
The History Command
History command shows all the basic commands in Linux that you have used in the
past for the current terminal session. This can help you refer to the old commands
you have entered and re-used them in your operations again.
Command Description
Joins two files (file1, file2) and stores the output in a new
cat file1 file2 > file3
file (file3)
mv file “new file path” Moves the files to the new location
mv filename
Renames the file to a new filename
new_file_name
mv Renames a directory