Linux command
Wednesday, April 8, 2009
Some Important Commands:
Before we start, we must commit not to delete files except those, that are created by us.
Lets go…..
Log in as root
pwd is used to display full path name of the current directory.
cd command changes the current directory to a specified directory.
Example – cd /usr/bin
~ sign specifies full path for your home directory
mkdir is used to create a directory. Example – mkdir new (will create directory in the current directory) mkdir /home/new (will create directory under /home)
mkdir –p /all/{tom,dic,harry}/{old,new}
The above command will create tom, dic and harry directories in /all and also creates old and new directory in each tome, dic and harry directory.
ls is used to display list of files and directory.
ls –l displays a detail list of files and directories, indicating directory/file, file acess
permission, link ,file, directory, owner, group owner, size in bytes,creation date and time
and name of directory/ file. In the first field, “-“ indicates “file”, “d” indicates directory”.
ll will also gives the same result as ls –l.
ls –la or ll -a list all files including the hidden files.
ls –R –l recursive listing of files, includes contents of the specified/current directory and all the subdirectories.
ls –r –l displays files and directory in reverse order.
ls –s –l list files, sorts by file size.
cp command is used to copy file. Example – cp file1 file2 (here file1 is source file and
file2 is the destination).
cp /etc/* . (copy all files from the /etc directory into the current position)
cp –r file_name destination_directory (Copy file to destination and preserve
permission, ownership and time stamps)
cp –r /etc/* /home/user1 copy all files and directories, including subdirectories in
/home/user1directory.
rm * delets all files from the current directory. Here the system will ask your
confirmation. Only files will be deleted.
rm –f * deletes all files from the current directory forcefully. The system will not ask your confirmation before deleting files.
rm –Rf * this command removes all files and subdirectories
cat command is used to display contents of a file. Example – cat file1
cat > file2 command allows you to create file, named as file2, and it gives you an interface to add contents to this file. However after adding contents we can save the file using+d command.
cat file1 file2 > file3:it create a file, named file3, with the contents of file1 and file2
cat file1 > file2 (here, the contents of file2 will be overwritten by the contents of file1)
cat file1 >> file2 (here, the contents of file1 will be appended to the contents of file2)
touch command can be used to create file/files with no contents. Example -
touch file_name1 file_name2 file_name3
echo command is used display any string
rmdir deletes directory. Example rmdir /home/new. This command will remove /home/new directory if it is empty.
rm deletes file. Example rm file1
date command displays current date & time
clear will clear the console screen.
df –h displays partition(s) and space used in partitions
w OR who is used to view who are logged on to this server
useradd or adduser is used to create user object.Example: useradd user_name
passwd - a user can change his password using this command
passwd user_name :If root user wants to change the password for any user
Here are some important passwd commands: -
passwd –d user-name (will empty password for that user)
passwd –l user-name (will lock the user account)
passwd –u user-name (will unlock the user account
Before we start, we must commit not to delete files except those, that are created by us.
Lets go…..
Log in as root
pwd is used to display full path name of the current directory.
cd command changes the current directory to a specified directory.
Example – cd /usr/bin
~ sign specifies full path for your home directory
mkdir is used to create a directory. Example – mkdir new (will create directory in the current directory) mkdir /home/new (will create directory under /home)
mkdir –p /all/{tom,dic,harry}/{old,new}
The above command will create tom, dic and harry directories in /all and also creates old and new directory in each tome, dic and harry directory.
ls is used to display list of files and directory.
ls –l displays a detail list of files and directories, indicating directory/file, file acess
permission, link ,file, directory, owner, group owner, size in bytes,creation date and time
and name of directory/ file. In the first field, “-“ indicates “file”, “d” indicates directory”.
ll will also gives the same result as ls –l.
ls –la or ll -a list all files including the hidden files.
ls –R –l recursive listing of files, includes contents of the specified/current directory and all the subdirectories.
ls –r –l displays files and directory in reverse order.
ls –s –l list files, sorts by file size.
cp command is used to copy file. Example – cp file1 file2 (here file1 is source file and
file2 is the destination).
cp /etc/* . (copy all files from the /etc directory into the current position)
cp –r file_name destination_directory (Copy file to destination and preserve
permission, ownership and time stamps)
cp –r /etc/* /home/user1 copy all files and directories, including subdirectories in
/home/user1directory.
rm * delets all files from the current directory. Here the system will ask your
confirmation. Only files will be deleted.
rm –f * deletes all files from the current directory forcefully. The system will not ask your confirmation before deleting files.
rm –Rf * this command removes all files and subdirectories
cat command is used to display contents of a file. Example – cat file1
cat > file2 command allows you to create file, named as file2, and it gives you an interface to add contents to this file. However after adding contents we can save the file using
cat file1 file2 > file3:it create a file, named file3, with the contents of file1 and file2
cat file1 > file2 (here, the contents of file2 will be overwritten by the contents of file1)
cat file1 >> file2 (here, the contents of file1 will be appended to the contents of file2)
touch command can be used to create file/files with no contents. Example -
touch file_name1 file_name2 file_name3
echo command is used display any string
rmdir deletes directory. Example rmdir /home/new. This command will remove /home/new directory if it is empty.
rm deletes file. Example rm file1
date command displays current date & time
clear will clear the console screen.
df –h displays partition(s) and space used in partitions
w OR who is used to view who are logged on to this server
useradd or adduser is used to create user object.Example: useradd user_name
passwd - a user can change his password using this command
passwd user_name :If root user wants to change the password for any user
Here are some important passwd commands: -
passwd –d user-name (will empty password for that user)
passwd –l user-name (will lock the user account)
passwd –u user-name (will unlock the user account
1 Comments:
Thanks. for this.
Post a Comment