Commands
Essential Unix commands
You will be using these constantly from this point on, so feel free to print them out on a cheat sheet.
ls
Action: List files.
Notes: If you don't provide a folder it will look in the current folder. Often it's useful to see the list in a vertical format. You can do that using the -l. option.
Examples:
ls stuff/: list contents of the stuff/ folder
ls -alh: list contents of the current directory vertically
cd
Action: Change into another directory.
Notes: Can go up one level in the directory tree by using ...
Examples:
cd stuff/: Change to the stuff/ directory.
cd ..: Go up one level.
cd ../../other: Go up two levels and change to the other directory.
mkdir
Action: Create an empty directory.
Notes: Can use -p option to make multiple sub-directories quickly.
Examples:
mkdir stuff: Create the stuff/ directory.
mkdir -p work/ironhack/assignment1: Create the work/ with ironhack/assignment1 directories inside.
rm
Action: Remove a file or directory.
Notes: Use -r option for deleting directories.
Examples:
rm file.txt: Delete the file.txt file.
rm -rf work/ironhack/assignment1: Delete the work/ironhack/assignment1 directory.
cp
Action: Copy a file or directory.
Notes: Takes two parameters: source and destination. Can use wildcard in source * to copy files that match a pattern. Use -r option for directories.
Examples:
cp program.rb app.rb: Copies program.rb to app.rb.
cp stuff/*.html html-files/: Copies all files in stuff/ that end in .html into the html-files/ folder.
cp stuff/ stuff-copy: Copies the stuff/ directory as the stuff-copy/ directory.
mv dir - move directory
mv
Action: Move and/or rename a file or directory.
Notes: Takes two parameters: source and destination. Can use wildcard in source * to move files that match a pattern. If the destination is a folder, it will move the files into the folder and leave the file's name unchanged.
Examples:
mv program.rb app.rb: Renames program.rb to app.rb.
mv program.rb stuff/: Moves program.rb into stuff/.
mv stuff/*.html html-files/: Moves all files in stuff/ that end in .html into the html-files/ folder.
more
Action: Output the contents of a file.
Notes: Use the spacebar or arrow keys to navigate a long files. Use the q key to quit out of it.
Examples:
more program.rb
pwd
Action: Show the current directory.
Notes: Short for print working directory, not password (I know!). Doesn't take any options, just use it as-is to remind yourself where you are.
Examples:
pwd
Commands
ls (list files)
-l (prints long form of file list)
-a (show all files, including hidden files)
clear (clear the screen)
create file
- touch program.js
cd (change directory)
cd ~ (go to home directory) - cd .. (go up to directory - file path)
pwd (print working directory)
~/desktop ( ~/ is a shorcut - go to the directory desktop)
cat (print content on the console)
less (print content on the console) - check differences
control z (go back inside the document on less)
mv (move files rename it)
cp (copies file or directory)
rm (remove)
mkdir (make a directory)
whoami ( Who I am? user)
----
Users
whoami (Displays the user you are logged in)
sudo adduser (sudo add user)
su (switch user - allow to log in as a different user)
exit (takes out from the session with the other user)
chmod (changes the permissions (mode) of a file or directory)
chown (changes the owner of a file or directory)
sudo (Run a command as the super user)
sudo !! (Run the previous command as the super user)
!! (represensts the most recently run command