Print the present working directory with full path
user1@raj:~/hadoop> pwd /home/user1/hadoop
List contents of a Directory OR shows contents of the current directory if no directory is specified
//List content of the directory /home ls /home //List content of the current directory ls //List contents of the Directory /home in long listing fashion ls -l /home OR ll /home //List contents of the current Directory in long listing fashion ls -l OR ll //List contents of the directory /home in increasing order of Last modified Time ls -ltr /home //List contents of the current directory in increasing order of Last modified Time ls -ltr //List contents(including hidden files) of the Directory /home ls -a /home //List contents(including hidden files) of current Directory ls -a
Changes current working directory to the given directory.
//Change current working directory to the /home/hadoop directory cd /home/hadoop //Go to the parent directory of the current directory cd .. //Go to the home directory of the logged in User cd ~ //Go to the last visited directory cd -
This command is used to remove a file or Directory
//Remove the file /home/hadoop/example.txt rm /home/hadoop/example.txt //Remove all the contents of the directory /home/hadoop recursively. //This will delete all the files and sub-directories of the given directory rm -r /home/hadoop
Copy a file or Directory from one location to another location.
//Copy the file example.txt from the current directory to /home/hadoop directory cp example.txt /home/hadoop //Copy the hadoop directory to /home/backup/ directory recursively. //This will copy all the files and sub-directories of the given directory to the target directory cp -r /home/hadoop /home/backup
Move the file or directory from one location to another.
//Move the file /home/hadoop/abcTest.txt to the location /home/hadoop/examples/ mv /home/hadoop/abcTest /home/hadoop/examples/ OR mv /home/hadoop/abcTest /home/hadoop/examples/abcTest.txt //Move the directory /home/hadoop/wordcount to /home/hadoop/examples mv /home/hadoop/wordcount /home/hadoop/examples
tail command is used to print the data at the end of the file. By default it prints last 10 lines.
//print the data at the end of the file examples.txt. By default it prints last 10 lines. tail examples.txt //Print n number of lines from the tail of the file. //This will print last 20 lines from the file examples.txt. tail -n 20 examples.txt //Print the real time data from the end of a growing file. //If the file is being written by some other process, //then the current data being added to the file will get printed. //For e.g. This command can be used to see the data being written to a log file. //Press CTRL-C to terminate the command. tail -f examples.txt
ps command is used to display information about the running Processes.
//List all the running processes ps -ef //List all the running processes and show hierarchy ps -efH //List all the running processes for the current logged in user ps fux
tar command is used to handle tar files.
//Create tar file from the content of the directory /home/hadoop tar -cvf hadoop.tar /home/hadoop //Extract the content of the tar file hadoop.tar to the directory /home/hadoop/extract/ tar -xvf hadoop.tar /home/hadoop/extract //List the contents of the hadoop.tar tar -tvf hadoop.tar //Append to archive. Add file examples.txt to the archive hadoop.tar tar -rvf hadoop.tar examples.txt
scp is a command which files to be copied to, from, or between different hosts.
//Copy the file examples.txt from a remote host to the /home/hadoop directory of the localhost scp username@remotehost:examples.txt /home/hadoop //Copy the file example.txt from the localhost to a remote host's /home/hadoop/samples directory scp examples.txt username@remotehost:/home/hadoop/samples //Copy the directory /home/hadoop/examples from the local host to a remote host's /home/user1 directory scp -r /home/hadoop/examples username@remotehost:/home/user1/
df command is used to see the amount of disk space used on each mounted filesystem.
//This will display the output in bytes. df //To display output in readable formats like Kb, Mb, GB, use this command. df -h
Some commands to use vi editor.
//Go to insert mode and start editing i //Go to the command mode esc //Go to any line number n shift:n //Save the current file and exit shift:wq //Exit the current open file without saving shift:!q /Find the text in the file. Press n to find next occurrence of the text in the forward direction //and N to find the next occurrence of the text in backward direction. shift:/text
The sudo (super user do) command allows a permitted user to execute a command as the superuser.
du -sh directory OR shows stats about current directory if no directory is specified
gives the hostname of the machine
Check whether any process is running on a given port
netstat -npl | grep 10000