File Management π
ββ’ Change Directories
ββ’ List Files
ββ’ Current Directory
ββ’ File Contents
ββ’ File Creation
ββ’ File Deletion
ββ’ Copy Files
ββ’ Move Files
ββ’ Compare Files
ββ’ Symbolic Links
Permission Manipulation πΌ
ββ’ Accessors
ββ’ Permissions
ββ’ Symbolic vs Absolute
ββ’ Change Ownership
ββ’ Set Permissions
Packaging π¦
ββ’ Sync Package List
ββ’ Query Packages
ββ’ Install Packages
ββ’ Delete Packages
ββ’ List Packages
ββ’ Package Information
Source Control
ββ’ Clone Repositories
ββ’ Stage Files
ββ’ Commit Files
ββ’ Upload Files
ββ’ angle brackets <required argument>
ββ’ square brackets [optional option]
ββ’ curly braces {default values}
ββ’ parenthesis (miscellaneous info)
ββ’ hastag # comment
In Linux everything is a file. Directories are just a list of files and for that reason, many programs such as ls
and mv
don't disctriminate
change to a directory (home)
cd [dirPath]
list all files in a directory (current)
ls [dirPath]
# including hidden
ls -A [dirPath]
return path to working directory
pwd
output file content to terminal
cat <filePath>
# first <N> lines
head <N> <filePath>
# last <N> lines
tail <N> <filePath>
make file
cat [someText] > <filePath>
# join two files into a new file
cat <filePath> <filePath> > <filePath>
# make directory
mkdir <dirPath>
rm <filePath>
# and directories
rm -r <dirPath>
# recursive force (without confirmation)
rm -fr <dirPath>
copy files to a destination directory
cp <filePath> <dirPath>
# and directories
cp -r <dirPath> <dirPath>
move files/directories to a destination
mv <filePath> <dirPath>
# rename a file
mv <fileName> <newFileName>
check the difference between two files
diff <filePath> <filePath>
create a link pointing to target file (shortcut)
ln -s <filePath> <linkName>
Every file on a Linux system has read, write & execute permissions defined per user, group & other
[u
]ser β who created the file
[g
]roup β set of users with common permissions
[o
]ther β anyone who isn't user or in groups
[a
]ll β all of the above (ugo
)
[r
]ead β view file contents
[w
]rite β edit/modify file
e[x
]ecute β run executable or view directory
none - no rights (-
)
symbolic ο½ absolute, read, write & execute per user, group & other command sequence table
β’ | u | g | o | ug | uo | go | a |
---|---|---|---|---|---|---|---|
r | u=r ο½400 |
g=r ο½040 |
o=r ο½004 |
ug=r ο½440 |
uo=r ο½404 |
go=r ο½044 |
a=r ο½444 |
w | u=w ο½200 |
g=w ο½020 |
o=w ο½002 |
ug=w ο½220 |
uo=w ο½202 |
go=w ο½022 |
a=w ο½222 |
x | u=x ο½100 |
g=x ο½010 |
o=x ο½001 |
ug=x ο½110 |
uo=x ο½101 |
go=x ο½011 |
a=x ο½111 |
rw | u=rw ο½600 |
g=rw ο½060 |
o=rw ο½006 |
ug=rw ο½660 |
uo=rw ο½606 |
go=rw ο½066 |
a=rw ο½666 |
rx | u=rx ο½500 |
g=rx ο½050 |
o=rx ο½005 |
ug=rx ο½550 |
uo=rx ο½505 |
go=rx ο½055 |
a=rx ο½555 |
wx | u=wx ο½300 |
g=wx ο½030 |
o=wx ο½003 |
ug=wx ο½330 |
uo=wx ο½303 |
go=wx ο½033 |
a=wx ο½333 |
rwx | u=rwx ο½700 |
g=rwx ο½070 |
o=rwx ο½007 |
ug=rwx ο½770 |
uo=rwx ο½707 |
go=rwx ο½007 |
a=rwx ο½777 |
set a user (and group) to a file
chown <user>[:group] <filePath>
define permissions per user, group & other of file
chmod <permissions> <filePath>
Installing programs in Linux is a bit different than on Windows. When you need a specific program, it's best to use your system's package manager to install software. Package managers handle dependencies, upgrading, querying, installing, removing, listing packages and much more. They severly reduce the complexity of installing software for the end-user
upgrade packages & sync repositories
# arch linux
pacman -Syu
# debian
apt update && apt upgrade
search for a package
# arch linux
pacman -Ss [package]
# debian
apt search [package]
install a package
# arch linux
pacman -S <package>
# debian
apt install <package>
uninstall a package
# arch linux
pacman -Runss <package>
# debian
apt purge <package>
list installed packages
# arch linux
pacman -Qe
# debian
apt list --installed
# arch linux
pacman -Si <package>
# debian
apt info <package>
Using below methods to clone an existing (empty) repository, means we can skip several unecessary, over-complicated commands
download a repositories contents (& .git)
git clone https://github.com/<user>/<repository>
# or a specific branch
git clone -b <branch> --single-branch https://github.com/<user>/<repository>
οΉ‘ although this command uses github as a refrence, any suitable version control software should work as intended
add new or changed files to the staging area
git add .
snapshot staged files with a message
git commit -m 'initial commit'
upload staged files
git push