Command Line Basics Flashcards
What is the $ in the command line?
It is the prompt or command prompt
What is the command line?
A user interface that’s navigated by typing
A way to interact with the computer using text and keywords
The command for the current machine and user name
Windows 10
$ whoami
scratchnsniff\jesse agar
Cloud 9
$ whoami
Ec2-user
Where does just the command cd take you?
What’s the difference between root, home, and user’s home and how do you get to each place
Takes you to user’s home direction (not the home folder)
Same as going
$ cd ~
The directory contains everything.
/home/user (c9 takes you to user when going “home”)
Including the home directory. Every user has their own home directory that contains pictures, music, personal files etc.
Root
cd /
Home
cd /home
User’s Home
cd ~
or
cd
Show files in current directory
$ ls
Show hidden files and folders
Show only hidden files and folders
$ ls -a
$ls -d .*
Show longform info on files and folders
(Shows the following: file mode, number of links, owner name, group name, number of bytes in the file, abbreviated month, day-of-month file was last modified, hour file last modified, minute file last modified, and the pathname)
$ ls -l
l for long form
(l for lots of info)
Show longform info on files and folders but with size in kb, mb, and gb as needed rather than just bytes
$ ls -lh
h for Human readable
Show files and folders by size
$ ls -s
s for size
Show files and folders by date modified
$ ls -t
Show files and folders by reversed (of whatever other flags)
$ ls -r
Create a file or update it’s date.
How do you do multiple files?
$ touch
‘Touch’ a file in memory. Creates files. Updates their ‘modified date’.
For multiple files separate by space
$ touch index.html script.js style.css
Keyword for home directory
Keyword for root directory
Where are they relative to one another
~
/
/home/ec2-user
~ and cd bring you to ec2-user, not home, on C9
Keyword for previous directory
..
Keyword for current directory
.
Can be used as a shortcut to add everything in this directory:
$ git add .
Autocomplete a name in terminal
How does it behave if multiple files have the same common letters?
tab while typing a name
Will complete the directory or filename
It will autocomplete up to the most common letter among the options
If there are no more common letters but multiple options, press tab again and it will show you the options
Display name of the current directory
$ pwd
Rename a file
mv oldfile.txt newfilename.txt
Also how you move a file
Move a file
mv oldfiledirectory.txt newfiledirectory.txt
Also how you rename
Create a directory
$ mkdir
Create nested directory
Create a series of nested directories
$ mkdir -p directory1/directory2
p for parent
Create a directory in the previous directory
$ mkdir ../newdirectory
Create directory and print the results of mkdir to console
$ mkdir -v for Verbose
Copy a file
$ cp sourcefilename.txt directory/filename2.txt
Copy files and prints results to console
$ cp -v
Copy directory
$ cp -r
Copy and force overwrite (not required for same user)
$ cp -f
Only needed when overwriting the file of another user
Copy and prompt overwrite
$ cp -i
i for interactive
Delete a file
$ rm
Delete a directory
$ rm -r
Chain commands, redirect the output of one command into another.
pipe operator
Ex:
ls -a ~ | grep _ | sed “s/_/-/g”
ls all files indirectory
Find files with _
Replace _ with -
Write the output of a command to file
> ls -a ~ | grep _ > underscores.txt
Ex:
Listing 1.39: $ cat underscores.txt
.DS_Store
.bash_history
.bash_profile
.guard_history
.pry_history
.psql_history
.rediscli_history
.scala_history
Read from file
<
Pipe that information from a file into a command
Create an identical copy of a file that gets updated as the source file is updated.
What happens if source file gets deleted?
$ ln sourcefilename.txt targetnewfilename.txt
If source if deleted, target survives as independent file.
Force a file to become the backup target of another
$ ln -f
ln sourcefilename.txt targetfilename.txt -f
Overwrites the existing file.
Create an identical copy of a file on a different file system and for directories.
Symbolic copy
ln -s a.txt b.txt
Because it works for directories and different file systems, its much more common.
Relative vs absolute path
If it starts from root (/) it’s absolute
starting from current location it’s relative.
check node version
$ node -v
install readline sync so you can have input in JS programs without a browser
$ npm install readline-sync –save
Get the manual for a command
$ man (any command)
sudo stands for…
superuser do
It’s the master key to your high-privilege admin tasks.
Go 2 folders up, 3 folders up
cd ../..
cd ../../..
List all files that follow a certain name pattern
use * to indicate any characters or number of characters
Copy all the contents of a folder
cp folder/* folder2
View a tree view of all folders from the current directory or specific direction
tree
tree folderName
list only hidden files
what else does the command do?
ls -d .*
what’s the difference between /foldername and foldername/
/foldername is looking at the root directory
foldername/ is looking from the current directory
Find an executable’s location
which executable
ex:
which touch