file management
cd Command
cd – change directory
cd . – the working directory
cd .. – the working directory’s parent directory
cd ~ – change to home directory
clear – clear the screen
ls Command
ls – list file and directories
ls -a – list all including hidden files
ls /bin – list the files in the /bin directorty
ls -l – list the files in a long format
ls -l /etc /bin – list the files in both the /etc and /bin directories in long format
ls -al – list all files including the ones beginning with . in long format
ls -la .. – list all files including the ones beginning with . in long format
ls -l /proc | less – when viewing large files as it allows you to scroll up and down
Manipulating Files
cp – copy files and directories
cp filename filename.backup – copies filename to filename.backup
cp -a /home/nexus/new_design/* /home/nexus/public_html/ – copies all files, retaining permissions form one directory to another.
cp -p file1 file2 – Copy file1 to file2 preserving the mode, ownership and timestamp
cp -i file1 file2 – prompt for confirmation before overwritting it
Create A File
touch – create an empty file
touch /home/nexus/public_html/404.html – create an empty file called 404.html in the directory /home/nexus/public_html/
Move Files or Directories
mv – move or rename files and directories
mv -i file1 file2 – Rename file1 to file2
Make a Directory
mkdir – create directories
Remove Files or Directories
rmdir – remove directories
rm – remove files and directories
rm -f filename.txt – deletes filename.txt, will not ask for confirmation before deleting.
rm -rf tmp/ – recursively deletes the directory tmp, and all files in it, including subdirectories. BE VERY CAREFUL WITH THIS COMMAND!!!
rm -i filename.txt – get confirmation before removing the file example – recursively removes all files and directories under the example directory
rm -rf * – deletes everything in the directory BE VERY CAREFUL WITH THIS COMMAND!!!
rm file? – remove all files called file with one digit
rm file?? – remove all files called file with two digits
echo “” > filename – deletes the contents of the file but not the file itself
To delete contents of the file but not a file itself
echo -n > YOURFILE
cat /dev/null > YOURFILE
du /var/log/* -s | sort -rn | head
cat /dev/null > /var/log/btmp
View the Contents of a File
cat – dispays contents of a file
cat > –
less – displays a file a page at a time
head – displays the first few lines of a file
tail – displays the last few lines of a file
tail /var/log/messages – see the last 20 (by default) lines of /var/log/messages
tail -f /var/log/messages – watch the file continuously, while it’s being updated
tail -200 /var/log/messages – print the last 200 lines of the file to the screen
more – like cat, but opens the file one screen at a time rather than all at once
more /etc/userdomains – browse through the userdomains file. hit to go to the next page, “”””to quit
Text Editors
vi – another editor, tons of features, harder to use at first than pico
vi /home/nexus/public_html/index.html – edit the index page for the user’s website.
esc i – to edit file
esc :wq – to save and quit
esc :q! – to not save and quit
pico – friendly, easy to use file editor
pico /home/nexus/public_html/index.html – edit the index page for the user’s website.
File Search
grep – looks for patterns in files
grep root /etc/passwd – shows all matches of root in /etc/passwd
grep -v root /etc/passwd – shows all lines that do not match root
wc – count number of lines/words/chanracters in a file
Find Command
find ~ -name passwords.txt – start in home directory and look for files called passwords.txt
find -name *hawaii* – find files called hawaii
find -mmin +0 -mmin -10 – find files modified in the last 10mins
find -mmin +0 -mmin -120 | less – find files modified in the last 120 minutes
find / -name *.local –
locate file – find all instances of file
Looking Around
File Command
file – classify a file’s contents
file – attempts to guess what type of file a file is by looking at it’s content.
file * – prints out a list of all files/directories in a directory
File Permissions
User Group Other
rwx rwx rwx
— — —
421 421 421
Directory Modes
7 rwx – Full Access
5 r-x – Limited Access (enter,read)
0 — – No Access
chmod 750 <Name of Directory>
Modify Permissions
chmod -R number folder name – change the permissions for everything in the directory
chmod number folder – change the permissions for one folder
chown -R user.group – change the owner and group for everything in the directory
chown user.group folder – change the owner for one folder
Changing File Permission
chmod 777 /var/www/vhosts/default/htpdocs/unsecuredfolder
cd /var/www/vhosts/httpdocs/domain
then chmod 777 to change the folder permission
or
/var/www/vhosts/httpdocs/domain/folder name / chmod 777 -R upgrade
chmod 777 -R —-to cover folder and all files
chmod 777 ———-to cover just files
Changing Multiple Folder/File Permissions
To change the parent folder and the sub folders permissions.
find /path/to/domain -type d -exec chmod 755 {} \; – changes directory and sub directory permissions to 755
find /path/to/domain -type f -exec chmod 644 {} \; – changes files and sub directory file permissions to 644
/var/www/vhosts/domain/httpdocs
Change Owner Permissions
chown [Name of User] [Name of Directory] – Changes the owner of the Directory
chown [Name of User].[Name of Group] [Name of Directory]
Change Group Permissions
chgrp [Name of Group] [Name of Directory] – Changes the Group of the Directory
newgrp [Name of Group]
Change Owner and Group Permissions
chown -R [Name of User]:[Name of Group] [Name of Directory]
chown -R ffchallenge:psacln ./httpdocs
Make a User and Admin of a Group
gpasswd -A [Name of User] [Name of Group]
Add User to Group
gpasswd -a [Name of User] [Name of Group]
cat /etc/group
groups [Name of User]
Remove User from Group
gpasswd -d [Name of User] [Name of Group]
cat /etc/group
groups [Name of User]