Some Basic Commands in Linux
Basics commands in Linux
The ls command
ls ----- Command is equivalent of the DOS dir command. It lists the files and subdirectories contained within the present directory.
Some possible flags which can be used with the ls command are:
ls -a List all files including hidden files which starts with.(Dot).these hidden files will not be displayed with simple ls command
ls | more Lists files and directories page after page on keystroke. The above command actually is a combination of two commands. It introduces a new concept called
ls –R It lists the files and subdirectories of a directory and further lists the contents of each subdirectory recursively. The ou
pwd The pwd or the present working directory command gives you the path to the directory in which you presently are. It is used without flags simply as
su Many times you might have logged in as a normal used and might need to be root to install a software or for some other small task. You could logout then login as root complete the work logout and login back as a normal user. Instead, you can just use the su command. The format is:
e.g.: su root
whoami It will tell you which user you are logged in as. Useful when you have used
cp This one copies files / directories from one place to another its syntax is
cp source_file_with_path destination_path
e.g.: cp /home/bala/secret.txt /f
This would make a copy of secrets.txt from /home/bala to /f
cp –i Interactive copying, prompts before overwriting files or directories
cp -l source_file_with_path destination_path
Makes a link (shortcut) to the source_file at the destination path instead of actually copying it there.
cp –p Preserve file attributes while copying if possible
cp –R Copy Recursively. Used when copying directories. This command also copies the contents of the subdirectories.
cp –u Update i.e. Copy only if the source file is newer than the destination file or the destination file does not exist.
rm The rm command is used to remove or delete files or directories. Its general format is:
rm -flag file_or_directory_with_path
Eg: rm /home/bala/recycle.txt
Some flags which can be used with the rm command are
rm -v test.txt
Remove verbosely, explain what is being done.
rm -r directory
Remove the directory and its contents recursively.
mkdir This command is used to create new a new directory. Its syntax is
mkdir -optional_flag directory_name
The possible flags are
mkdir -v directory_name
Tell what is going on.
mkdir -p directory_with_path
This is a cool command. Suppose you need a directory named data within another directory called report in /usr/local and the parent directory report itself does not exist, then you can use :
mkdir -p /usr/local/report/data
This command creates the report directory and the data subdirectory in one go.
man For someone new to linux, the man command is one of the most important commands. The syntax is:
Suppose you have not understood fully one of the above commands or want to find out about a new command you have learnt, the man command provides a manual for that command