Docs
Search…
Command Line Basics
Command
Description
pwd
print working directory (current location)
ls
list directories & files in current directory
cd ..
back up one directory
cd
back up to the home directory
cd myDirectory/
open myDirectory
mkdir exp1
makes a directory-exp1
nano file1
opens file1 in nano editor
cp file1 /home/User.name/exp2
copies file to exp2 (current location must be
the original location of file1)
mv file1 /home/User.name/exp2
copies file to exp2 (current location must be
the original location of file1)
mv file1 ./exp1 ./exp2
moves file1 from exp1 to exp2 (exp1 & exp2
are both in the current directory (denoted by period (.))
rm file1
removes file1 from current directory
whoami
returns username
echo Hello World
prints Hello World
to the terminal

Command Line Basics (with examples)

First, we will use the pwd (print working directory) command to show our current location.
2
/home/Joseph.Madison
Copied!
We can also list the files in out current working directory.
2
demo_files dissertation_research install_files
Copied!
To move to the demo_files sub-directory, we can use the cd (change directory) command. We can follow this up with the pwd command to verify we have moved to the demo_files sub-directory.
1
[[email protected] ~]$ cd demo_files
2
[[email protected] demo_files]$ pwd
3
/home/Joseph.Madison/demo_files
Copied!
We can also move backward in our directory line using the cd .. command. Here we will move from the demo_files back to the Joseph.Madison directory.
1
[[email protected] demo_files]$ cd ..
3
/home/Joseph.Madison
Copied!
Next, we will make two new directories in the Joseph.Madison directory. We can do this using the mkdir command. We will call our directories exp1 and exp2. Verifying that the two new directories were created can be done by using ls.
1
[[email protected] ~]$ mkdir exp1
2
[[email protected] ~]$ mkdir exp2
4
demo_files dissertation_research exp1 exp2 install_files
Copied!
Next, we will make a text file in the exp1 directory. We first have to cd into the exp1 directory. It is again good practice to verify your location with pwd.
1
[[email protected] ~]$ cd exp1
2
[[email protected] exp1]$ pwd
3
/home/Joseph.Madison/exp1
Copied!

Making Files

Next, we will create a file using a text editor. Here we will use nano (there are others including emacs and vi, but nano is simple). We use the nano command followed by the name of what we want to call the new file. (Include a file extension if desired.)
1
[[email protected] exp1]$ nano file1
Copied!
Once you press enter you will be moved into the text editor. A cursor at the top of the page is where text will be entered as you type. This is a powerful tool with many applications but here I will type 'Hello World!'
1
GNU nano 1.3.12 File: file1 Modified
2
3
Hello World!
Copied!
I will then use ctrl-X to exit. This will give me a prompt for saving changes.
1
Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?
2
Y Yes
3
N No ^C Cancel
Copied!
Type y for yes. You will then be prompted to verify the file name, hit enter or change the original name and hit enter.
1
File Name to Write:file1
Copied!
You will then be brought back to the directory you put the file in. You can verify your location with pwd.
2
[[email protected] exp1]$ pwd
3
/home/Joseph.Madison/exp1
Copied!

Moving/Removing Files

You can also move the file you just made with the mv command. Here, I will move file1 from the exp1 directory to the exp2 directory. I will also change directories to the exp2 directory and verify my file was moved. Note: You must specify the entirety of the directory you are moving to, otherwise your file will just be renamed (mv can double over as a rename command).
1
[[email protected] exp1]$ mv file1 /home/Joseph.Madison/exp2
2
[[email protected] exp1]$ cd ..
3
[[email protected] ~]$ cd exp2
4
5
file1
Copied!
If you want to copy a file instead of moving it, you can use the cp command in the same manner.
1
[[email protected] exp1]$ cp file1 /home/Joseph.Madison/exp2
2
3
file1
4
[[email protected] exp1]$ cd ..
5
[[email protected] ~]$ cd exp2
6
7
file1
Copied!
The file is now in both locations.
Another command that is very useful and very dangerous is the remove command rm.
The HPC does not backup files so if you remove a file or directory it is gone (always have backup files elsewhere such as on your local PC!) Here I will remove file1 from exp2. You can ls and nothing should be there (you will be sent back to the command prompt.
1
[[email protected] exp2]$ rm file1
2
Copied!
Directories can also be removed using the rm -r command. This command will also delete any files contained in the directory. You first have to move the parent directory. After deleting you can verify it is no longer there using ls.
1
[[email protected] exp2]$ cd ..
3
/home/Joseph.Madison
4
[[email protected] ~]$ rm -r exp2
6
demo_files dissertation_research exp1 install_files
Copied!

Misc.

Another useful command is the whoami command. This command will tell you what user you are on the system (and is also a nice sanity check late at night)
1
[[email protected] ~]$ whoami
2
Joseph.Madison
Copied!
The last subject of discussion in this doc will be the echo command. The echo command can serve many functions such as calling shell and environment variable values. Here it is demonstrated by simply repeating what we enter.
1
[[email protected] ~]$ echo HPC is fun!
2
HPC is fun!
Copied!
Last modified 1yr ago