Skip to content

Instantly share code, notes, and snippets.

@valosekj
Last active November 2, 2023 14:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valosekj/01da6fab0063457d4a77e766313d23cb to your computer and use it in GitHub Desktop.
Save valosekj/01da6fab0063457d4a77e766313d23cb to your computer and use it in GitHub Desktop.
Basic shell commands

Basic shell commands

A few basic shell (bash, zsh, ...) commands for UNIX (Linux, MacOS) CLI (command-line interface)

1. File and directory manipulation commands

cd - change directory:

# change directory to /home/username/Downloads:
$ cd /home/username/Downloads

pwd - print path of the current/working directory:

# first, go to some directory
$ cd /home/valosek/Downloads
# then check its path
$ pwd
/home/valosek/Downloads

Note - echo $PWD returns same output as the pwd command

mkdir - make/create directory:

# make a new directory with name test_folder
$ mkdir test_folder

ls - list what is inside directory:

# check what is inside current directory
$ ls
# check what is inside given directory
$ ls test_folder
# check what is inside /home/username/Downloads directory
$ ls /home/username/Downloads

useful options for ls command:

ls -l - list view

ls -t - sorted by time

ls -a - show hidden files

ls -h - human readable form

ls -lath - all options together

ls -d - check folder itself (do not check what is inside)

cp - copy files or directories (cp -r)

# copy two files (my_file and my_file2) to /home/username/Downloads folder
$ cp my_file my_file2 /home/username/Downloads
# copy two folders (my_folder and my_folder2) to /home/username/Downloads folder
$ cp -r my_folder my_folder2 /home/username/Downloads

mv - rename (move) files

# first, create some directory
$ mkdir test_folder
# rename directory test_folder to test_folder_2
$ mv test_folder test_folder_2

rm - remove files or directories (rm -r)

# first, create some directory
$ mkdir test_folder
# remove directory test_folder
$ rm -r test_folder

2. Text file manipulation commands

nano - simple text editor for creating/modifying text file

$ nano my_file.txt

useful shortcuts for nano command:

ctrl + W - find

ctrl + O - save

ctrl + X - exit

gedit and atom - graphical text editors

# gedit - simple graphical text editor built-in in GNOME
$ gedit my_file.txt
# atom - advanced graphical text editor - https://atom.io/
$ atom my_file.txt

cat - show what is inside text file (print whole file into CLI)

$ cat my_file.txt

head - display the beginning of the file (first 10 lines)

$ head my_file.txt

Note - you can specify number of lines to print, e.g., head -20 my_file.txt

tail - display the end of the file (last 10 lines)

$ tail my_file.txt

Note - you can specify number of lines to print, e.g., tail -20 my_file.txt

3. Other miscellaneous commands

find - find files or directories

$ find $PWD -name 'some_file_name' -type f

useful options for find command:

-name filename - filename - name of file or directory (wildcards such as * can be used)

-type f/d - f - file, d - directory

-user usr - usr - owner of files

grep - find string inside text file

$ grep "my_string" my_file.txt

vncserver - start or stop a TigerVNC server

# start a new VNC session with certain display number (e.g., 5) and certain screen resolution
$ vncserver :5 -geometry 1650x1100
# OR
$ vncserver :5 -geometry 1650x1100 -localhost no

# kill certain VNC server
$ vncserver -kill :5

# connect to the VNC server
$ vncviewer :5

Note - if you get warning that VNC session is already running under certain display number, specify another free display number

Tip - vncserver can be configurated by ~/.vnc/xstartup file, e.g., my xstartup file for mate enviroment and zsh shell looks:

#!/bin/sh

unset DBUS_SESSION_BUS_ADDRESS
unset SESSION_MANAGER

export SHELL=/bin/zsh
exec /usr/bin/mate-session

4. Medical image viewer softwares

aeskulap - open source viewer for DICOM images

$ aeskulap folder_with_dicom_images/*

fsleyes - image viewer for neuroimaging data

$ fsleyes my_brain.nii.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment