Skip to content
This repository was archived by the owner on Jan 27, 2023. It is now read-only.

Useful Unix commands

Antonio Ulloa edited this page Mar 5, 2017 · 10 revisions

Below you will find a list of some of the most frequently used commands when using LSNM in a Unix/Linux workstation. Please note that they are not meant to be exhaustive.

How to tar and zip a directory prior to copying or transferring:

$ tar -cvzf file_name.tar.gz directory_name

How to unpack and unzip a tar.gz file:

$ tar -xzvf file_name.tar.gz

How to download a file from remote server:

$ scp username@remote.server.com:/home/username/myfile .

How to upload a local file to remote server:

$ scp mylocalfile username@remote.server.com:/home/username

To run a GUI-based program remotely, you need to tunnel the X-windows connection through the SSH connection as follows:

$ ssh -X username@remote.server.com

After pressing <Enter>, you will have to provide your remote server password.

How to execute same command on a number of files using a unix (bash) script loop. Let's say we want to execute

the script 'netgen.py' on all files in current directory with extension 'ws':

$ for file in *.ws; do
$     python netgen.py $file
$ done

How to execute jobs in a remote server and log out without terminating those jobs.

First, log in to the remote server using 'ssh' (see above), then execute the command:

$ screen -S <screen-name>

to open a virtual screen. Then execute your desired script(s) using 'nohup':

$ nohup python python_script.py &

Now you can disconnect from you screen typing <Ctrl><a><d>, which will disconnect you from the virtual screen. You can log out and later come back to the same virtual screen to check on your job(s) by logging in with 'ssh' and then typing:

$ screen -d -R <screen-name>

Do not forget to close your screen after you are finished with the jobs and data has been saved, by typing:

$ exit
Clone this wiki locally