Welcome To Uday RAGE Home Page
preloader

Basic linux commands

Symbols


~ represents users home directory . represents current directory .. represents parent directory of current directory

File commands


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

Directory commands


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

Printing the contents of a file


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

Other commands


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.

Linux advanced commands

1. SSH key generation and remote login

  1. Execute the below command and simply keep on pressing enter until it is done

    
    
    ssh-keygen
  2. Copy your public key to the remote server using the following command

    
    
    ssh-copy-id userName@serverIP
  3. Test the remote login

    
    
    ssh userName@serverIP

2. Setting up the config file

  1. Go into .ssh folder

    
    
    cd .ssh
  2. Create a file named ‘config’

    
    
    vim config
  3. 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
  4. Save the file and exit.

    
    
    :wq
  5. Change the file permission to 600

    
    
    chmod 600 config
  6. Try to remote login into the server from the terminal

    
    
    ssh petName E.g., ssh skytree

3. SCP: copying files between remote servers and local machines

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

3. Monitoring the process

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.

Linux professional commands

1. Nohup: Running a process in background (very important command)

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 &

2. Mounting remote folders to a directory in a local machine

Please refer to https://www.tecmint.com/sshfs-mount-remote-linux-filesystem-directory-using-ssh/