Command Line Flashcards
Prompt
$
For Amazon Linux
Cursor
Where anything typed will show up
echo
display text in output
pwd
present working directory
command format
[command] [arguments…]
man [command]
Displays manual for [command]
Type “q” to exit manual.
Command Line Uses
Restart servers Rename hundreds or thousands of files according to a prescribed pattern Manage system logs Set up scheduled tasks (cron jobs) Debug server issues Monkey patch code on a server Query data Set up databases and servers --- and many more
cd [directory]
change directory
by itself, changes to the home directory, and with argument goes to the indicated directory
ls
list files and directories in current directory
pwd
display the path of the current directory
touch
create a file
mkdir
make directory
rm
remove a file or directory
Is permanent!
cp
copy a file or directory
mv [source] [destination]
move or rename a file or directory movement is relative to current directory .. = parent directory . = current directory /[directory name] = child directory
cat
display contents of a file
more
displays contents of a file, starting at the top and letting the user scroll down
less
display contents of a file in an even ore interactive way
head
displays first part of a file
tail
displays last part of a file
cd /
change to parent directory
ls -1
lists files and directories in the current directory, each on a new row of output
cd ~
change to home directory
cd $HOME also works
q
exit current screen, eg “man”, “more”, etc.
clear
clears current output screen
/
root directory, or separator for listing directories
, or ./
current directory
.. or ../
parent directory
../..
grand parent directory
*
wildcard
ls -a
includes hidden files in list
“ ls -d .* “ lists only the hidden files
ls -lah
Get detailed information about the files and directories listed
which [command]
shows the directory where the executable exists for the [command]
env
display environment variables and values
variable=”value”
how to set an environment variable value
note that there are no spaces
ps1
environment variable for the prompt
.bashrc, .bash_profile
environment files (for bash, not Zsh) nano ~/.bashrc to edit
bin
binary: executable file
PATH
environment variable.
determines which directories are searched when a command is entered
an ordered, colon-delimited list of directories that contain executables
PATH can be amended to add directories for executables
to permanently change PATH: .bashrc
rwx
read, write, exectute
drwxrwxr-x 3 ec2-user ec2-user practice
rwx = read, write, execute
d | rwx | rwx | r-x | 3 |ec2-user | ec2-user | practice
directory | User wx | Group rwx | Other rwx | # files | user name | group name | file / directory name
chmod u-w test.txt
add write permissions for user to file test.txt
chmod 777 text.sh
set permissions on text.sh to read, write, and execute for all users, groups, others. Number Permission 0 No permission granted. 1 Can execute. 2 Can write. 3 Can write and execute (2 + 1 = 3). 4 Can read. 5 Can read and execute (4 +1 = 5). 6 Can read and write (4 + 2 = 6). 7 Can read and write and execute (4 + 2 + 1 = 7).
chmod 777 text.sh
set permissions on text.sh to read, write, and execute for all users, groups, others.
Number Permission
0 No permission granted.
1 Can execute.
2 Can write.
3 Can write and execute (2 + 1 = 3).
4 Can read.
5 Can read and execute (4 +1 = 5).
6 Can read and write (4 + 2 = 6).
7 Can read and write and execute (4 + 2 + 1 = 7).
groups
display the groups for current user
su
switch user
su - = switch to root user, password entry may be required
REPL
Read-Eval-Print-Loop