~ represents users home directory
. represents current directory
.. represents parent directory of current directory
touch fileName #Creates an empty file
vi fileName #Open an editor to write a file
mv sourceFileName destFileName #Rename a file
cp sourceFileName destFileName #Copy a file
rm fileName # deletes a file
mdkir directoryName #Creates a directory
cd directoryName #Move into the respective directory
cd .. #Move to parent directory
mv sourceDirectory destinationDirectory #Rename/Move a directory
cp -r sourceDirectory destinationDirectory #Copy a directory
rm -r directoryName #Deletes a directory
cat fileName #Prints the contents of a file
head fileName #Prints first 10 lines of a file. head -100 fileName prints first 100 lines
tail fileName #Prints last 10 lines of a file. tail -100 fileName prints last 100 lines
su -userName #To login as a different user
pwd #Prints the current working directory
top #Prints the details of various processes running on a system. Press 'q' to quit.
whoami #Prints the userName
history #Prints the history of commands executed on a shell
!! #Shortcut to execute the previous command
!number #Executes the command having the same number in the history. E.g., !109 executes the command 109 in the history.
kill -9 pid #Kills the process whose id is -9.
ln -s <sourceFolder> <folderToLink>
Example:
mkdir ~/linkFolder
ln -s /data/code ~/linkFolder
Note: you must create linkFolder before executing the folder.
Execute the below command and simply keep on pressing enter until it is done
ssh-keygen
Copy your public key to the remote server using the following command
ssh-copy-id userName@serverIP
Test the remote login
ssh userName@serverIP
Go into .ssh folder
cd .ssh
Create a file named ‘config’
vim config
Edit the file by entering the following details
Host petName
User studentID
Port 22
Hostname ipaddress
#Example
Host skytree
User s123000
Port 22
Hostname skytree1.u-aizu.ac.jp
Save the file and exit.
:wq
Change the file permission to 600
chmod 600 config
Try to remote login into the server from the terminal
ssh petName
E.g., ssh skytree
Command to copy local files to remote server
scp fileName userName@remoteServerIP:location
E.g., scp test.txt user@server.uAizu:~
#The above command copies text.txt into the home folder of the user
scp -r folderName userName0remoteServerIP:location
E.g., E.g., scp copyFolder user@server.uAizu:~
Command to copy remote files to local machine
scp user@server.uAizu:fileName localPath
E.g., scp user@server.uAizu:~/test.txt ~
scp -r user@server.uAizu:folderName localPath
E.g., scp user@server.uAizu:fileName localPath
Monitor the processes running on the server machine using the below command:
top
Press Control + C to quit. Use ‘kill’ command to stop any unwanted process.
Normally, big data programs may take several hours/days to execute. Thus, the common problem encountered by the researchers is that their programs often terminate when their remote terminals close due to session timeout, idle time, or network error. To evade this problem, users have to execute their programs using nohup command. The syntax is as follows:
nohup command &
E.g., nohup python bigDataProgram.py
When you want to execute nohup command with sudo, then first execute a random sudo command without nohup and provide the password. Next, execute the program.
sudo ls
#Enter the password when asked
nohup sudo command &
E.g., nohup sudo python bigDataProgram.py
The output of the nohup command will be saved in nohup.out. You can also redirect the output of nohup command to a specific file
nohup command >> outputFileName &
E.g., nohup python bigDataProgram.py >> output.txt &
Please refer to https://www.tecmint.com/sshfs-mount-remote-linux-filesystem-directory-using-ssh/