Command Line Crash Course
A quick introduction to the linux command line and frequently used commands.
NOTE: Do not update this page. This page is soft linked to IT - Sysadmin
> Linux
> Command Line Crash Course
. If you want to change the contents of this page, please change it on that page instead.
A quick introduction to the linux command line and frequently used commands.
NOTE: Do not update this page. This page is soft linked to IT - Sysadmin
> IT - Public How-To's
> Linux
> Command Line Crash Course
. If you want to change the contents of this page, please change it on that page instead.
A quick introduction to the linux command line and frequently used commands.
Paths
There are full paths and partial paths in linux. These behave similar to windows and other OSs
- Full paths begin with
/
in linux and specify the exact location of a file or folder (think of any paths that being with C:/ in windows) - Partial paths are relative to the currently directory they do not begin with any special symbols. (ie
cd somefolder/somefile
would tell linux to append somefolder/somefile to your current path and go there) - You can also specify current directory with a dot. (ie
cd ./somefolder/somefile
is the same as the previous bullet point) - Previous directory is specified with two dots (ie
cd ..
will take you up a directory) - You can also specify your home directory with
~
. Your home directory is the one that the terminal puts you in when you first login (usually /home/username)
Basic Common Commands
Here are some basic commands in linux that most people will want to use
cd <directory>
Change directories.
-
cd .
does not do anything -
cd ..
takes you up a directory -
cd ~
takes you back to your home directory
amdhome@biostats:~$ cd /srv/shiny-server/spins-abcd/
amdhome@biostats:/srv/shiny-server/spins-abcd$ cd .
amdhome@biostats:/srv/shiny-server/spins-abcd$ cd ..
amdhome@biostats:/srv/shiny-server$ cd ~
amdhome@biostats:~$
pwd
Print working directory: prints the current folder you are in
amdhome@biostats:~$ pwd
/home/amdhome
ls
List files and folders in the current directory
You can also specify a full or partial path to print that directories files/folders instead
You can append -al
for more information on the files
amdhome@biostats:/srv/shiny-server$ ls
index.html sample-apps spins-abcd
amdhome@biostats:/srv/shiny-server$ ls -al
total 12
drwxr-xr-x 3 root root 4096 Jun 13 13:37 .
drwxr-xr-x 3 root root 4096 Jun 13 12:41 ..
lrwxrwxrwx 1 root root 38 Jun 13 12:41 index.html -> /opt/shiny-server/samples/welcome.html
lrwxrwxrwx 1 root root 37 Jun 13 12:41 sample-apps -> /opt/shiny-server/samples/sample-apps
drwxr-xr-x 2 root root 4096 Jun 13 14:07 spins-abcd
mv <source> <destination>
Move file/folder. Both You also use this to rename things
amdhome@biostats:~$ ls
app.R
amdhome@biostats:~$ mv app.R app2.R
amdhome@biostats:~$ ls
app2.R
amdhome@biostats:~$ mv app2.R /tmp/
amdhome@biostats:~$ ls /tmp
app2.R
cp <source> <destination>
Copies files. You can specify -r
if you want to copy directories
rm <target>
Removes files.
You can append -r
to remove directories
mkdir <target>
Creates a folder
sudo
Sudo is a special command that lets you run commands with elevated (root) permissions. All you have to do is put sudo
at the beginning of a command. An administrator must have already granted you sudo rights in order to use this command
Exception
The only exception to this is cd
. This is because for most commands that you run, you are telling your shell (command line/terminal) to run a program. sudo
is a program that will run another program with elevated permissions. The cd
command is technically not a program, but a command to tell your shell to change state. Because cd
is not a program it can not be sudo-ed.
If you need to cd
to a directory that requires elevated permissions, you can just become root by using the command sudo -i
:
amdhome@biostats:~$ sudo -i
root@biostats:~$
Do be careful of any action taken while as root or when running with sudo as many sanity checks are bypassed when using linux as root.