BASH Flashcards
man
stands for manual, used to explain commands
$ ls
list directory contents
$ ls -l
use a long listing format
$ ls -a
all - do not ignore entries starting with .
$ ls -R
list all files and subdirectories recursively
$ cd
change directory - move between folders
% cd ..
return to previous directory
% pwd
print working directory - shows you full path of your current location
$ mkdir
make directory
% touch
change file timestamps
% touch -t 0402050000 new_file2.txt
change time of new_file2.txt to 05.02.04 instead of current time
% touch -r file1 file2
change file2 timestamps to copy file1s
% stat filename
can view access, modify, change, and birth info of file
% nano
text editor - lets you create/edit text files
% cp file1 file2
copy - copies content of file1 to file2
% mv
move and rename files
% mv desktop Desktop
will rename desktop as Desktop
$rm / rmdir
remove file or remove directory
shebang?
Very first line of a script
!/usr/bin/env bash
starter for portable bash script
echo “Hello World”
prints text to terminal
Would a new file be allowed to run?
No - newly created files aren’t executable by default, need to give permission to run them
chmod +x hello.sh
gives permission to run hello.sh
./hello.sh
./ tells terminal to run hello.sh file
$ printenv
prints environment variables
read -p can read for user input
yeah