More and more, I find myself using the command line (or Terminal on the Mac). I’m not sure if that says something about me, the current state of expectations for web developers or some combination of both.
Whatever the reason, I have decided to keep a list of all of the commands that I use. This list is really just for me to refer to later but I’m sure that others will also find it helpful.
I have to admit, using the command line scares me to death. This is likely a lack of confidence on my part. That coupled with the ability to really bork your system using some of these commands really makes me anxious when working in the Terminal (and doubly anxious when working on a server via SSH).
The command line is powerful. But, as Uncle Ben says, “With great power, comes great responsibility.” It would be easy to kill your entire system or server using some of the commands below so use with caution!
- cd (Change Directory)
- cd [another directory] example: move to directory “download” cd download
- cd ~ (How to go to home directory)
- cd - (How go to the last directory you were in)
- cd .. (How to go up a directory level)
- cd /volumes (Move to connect volumes ie Attached drives like Drobo)
How to show the full path of the current directory (Use this command to find out where are you currently in).
Scroll through previous commands
- up arrow
How to list files and/or directories in a directory
- ls (just type ls and hit enter)
- ls -a (shows all files and directories - even hidden)
- ls -al (list all files and information)
- ls *.ext (list all files ending with certain extension - ls *.php)
- ls -alh (list all files and folders with detailed information including file size)
How to quit and exit SSH client
- nano name of file.txt
- mv name\ of\ file.txt location\ to\ be\ moved\ to\
- mv Common\ Shell\ Commands.txt Documents
Can also be used for directories
- cp name\ of\ original\ file.txt name\ of\ new\ file.txt
- cp hello.txt hi.txt
- cp -r (-r stands for recursive meaning it applies to everything within the directory) name of directory to be copied name of new directory
- cp -r documents docs
Deleting Files and Directories
- rm name\ of\ file.txt
- rm -r name\ of\ directory
We need to recursively remove the directory and all of the files within the directory. Thus the -r flag.
Making a Directory
- mkdir (Make Directory) name\ of\ directory
- mkdir new\ directory
Making sub-directories - mkdir -p documents/notes/console/part1
Renaming a Volume, Directory, etc.
- mv /home/user/oldname /home/user/newname