Difference between revisions of "Basic Linux Commands"
(7 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
'''Basic File System Commands''' | '''Basic File System Commands''' | ||
− | ''' | + | '''cd''' - Change Directory |
'''cd Documents''' - Change to Documents Directory | '''cd Documents''' - Change to Documents Directory | ||
− | '''cd | + | '''cd home/pi''' - Change to pi Directory |
'''cd ..''' - Return one level up | '''cd ..''' - Return one level up | ||
− | '''cd /''' - root Directory | + | '''cd /''' - Change to root Directory |
'''pwd''' - Print Working Directory Absolute Path | '''pwd''' - Print Working Directory Absolute Path | ||
Line 17: | Line 17: | ||
'''rmdir rusty''' - Deletes a directory name rusty | '''rmdir rusty''' - Deletes a directory name rusty | ||
'''rmdir Documents/rusty''' - Deletes a directory named '''rusty''' in the folder '''Documents'''. | '''rmdir Documents/rusty''' - Deletes a directory named '''rusty''' in the folder '''Documents'''. | ||
− | '''rm''' | + | '''ls''' - Lists the content of the current directory |
+ | '''ls -l''' - Display additional information (permissions, owner, group, size, date and timestamp of last edit) | ||
+ | '''ls -al''' - Allows you to view files beginning with a dot (.). | ||
+ | '''tree''' - Show a directory and all subdirectories and files indented as a tree structure. | ||
+ | '''tree Documents''' Show the tree for the '''Documents''' directory. | ||
+ | '''tree /''' Show the tree for the '''root''' directory. | ||
+ | '''Basic File Handles''' | ||
+ | |||
+ | Write to a file and append to it each time | ||
+ | '''example: Ls -al >> filename.txt''' | ||
+ | Write to a file and write over any previous data | ||
+ | '''example: Ls -al > filename.txt''' | ||
+ | |||
+ | '''touch''' - Create file. | ||
+ | '''touch new.txt''' - Creates '''new.txt''' file with no data | ||
+ | '''touch Documents/rusty.sh''' - Creates a empty file named '''rusty.sh''' in the folder '''Documents'''. | ||
+ | '''rm''' - Remove File - Delete file | ||
'''rm rusty.sh''' - Deletes a file named '''rusty.sh''' | '''rm rusty.sh''' - Deletes a file named '''rusty.sh''' | ||
'''rm Documents/rusty.sh''' - Deletes a file named '''rusty.sh''' in the folder '''Documents'''. | '''rm Documents/rusty.sh''' - Deletes a file named '''rusty.sh''' in the folder '''Documents'''. | ||
− | '''cp''' | + | '''cp''' - Copy-Paste Copy file |
− | + | '''cp rusty.txt rusty2.txt''' - Copies the file '''rusty.txt''' and creates '''rusty2.txt''' with all attributes. | |
− | ''' | + | '''mv''' - Move File |
− | + | '''mv rusty2.txt Documents''' - Move the file named '''rusty2.txt''' to the '''Documents''' folder. | |
− | ''' | ||
− | |||
− | |||
'''cat''' - Display content of file. | '''cat''' - Display content of file. | ||
'''cat new.txt''' | '''cat new.txt''' | ||
+ | '''echo''' - Display text on Screen or Move text to file. | ||
+ | '''echo "Hello World"''' - Display Hello World on screen | ||
+ | '''echo My name is Rusty >> new.txt''' - Writes '''My name is Rusty''' into the file '''new.txt''' | ||
'''chmod''' - To make a file executable. | '''chmod''' - To make a file executable. | ||
− | '''chmod 777 rusty.sh''' | + | '''chmod 777 rusty.sh''' - Makes '''rusty.sh''' Executable and Readable. |
− | ''' | + | '''chmod u+x rusty.sh''' - Add execute permission for the owner of the file '''rusty.sh'''. |
− | ''' | + | '''chown''' - Changes the user and/or group that owns a file |
− | + | '''sudo chown pi:root rusty.txt pi:root''' | |
− | |||
− | |||
− | ''' | ||
'''head''' - Displays the beginning of a file | '''head''' - Displays the beginning of a file | ||
'''head -n 5 filename.txt''' Display the first 5 lines of file | '''head -n 5 filename.txt''' Display the first 5 lines of file | ||
Line 85: | Line 98: | ||
'''su rusty''' - Changes user to rusty (password needed for rusty) | '''su rusty''' - Changes user to rusty (password needed for rusty) | ||
'''last''' - Show a listing of last logged in users. | '''last''' - Show a listing of last logged in users. | ||
− | '''last -a''' - | + | '''last -a''' - Display hostnames in the last column |
− | '''last – F''' - | + | '''last – F''' - Print full login and logout times |
− | '''last – i''' - | + | '''last – i''' - Display IP numbers in numbers-and-dots notation |
'''users''' user that are loged in | '''users''' user that are loged in | ||
+ | |||
'''who''' - who is loged in and when | '''who''' - who is loged in and when | ||
'''who -a''' All options | '''who -a''' All options | ||
Line 97: | Line 111: | ||
'''who --version''' Output version | '''who --version''' Output version | ||
'''whoami'''- print effective userid | '''whoami'''- print effective userid | ||
+ | |||
+ | '''Basic Terminal Commands''' | ||
+ | |||
+ | '''history''' - Linux store any command you type in an archive file. | ||
+ | '''history -c''' - clear all the history | ||
+ | '''history -r''' - Read in the contents of the file | ||
+ | '''history -w''' - Overwrites the history file | ||
+ | '''history -d123''' - Delete line 123 | ||
+ | '''HISTCONTROL=erasedups''' |
Latest revision as of 03:51, 8 September 2019
Basic File System Commands
cd - Change Directory
cd Documents - Change to Documents Directory cd home/pi - Change to pi Directory cd .. - Return one level up cd / - Change to root Directory
pwd - Print Working Directory Absolute Path
mkdir - Make directory
mkdir rusty - Creates a directory named rusty mkdir Documents/rusty - Creates a directory named rusty in the folder Documents.
rmdir - Remove directory
rmdir rusty - Deletes a directory name rusty rmdir Documents/rusty - Deletes a directory named rusty in the folder Documents.
ls - Lists the content of the current directory
ls -l - Display additional information (permissions, owner, group, size, date and timestamp of last edit) ls -al - Allows you to view files beginning with a dot (.).
tree - Show a directory and all subdirectories and files indented as a tree structure.
tree Documents Show the tree for the Documents directory. tree / Show the tree for the root directory.
Basic File Handles
Write to a file and append to it each time example: Ls -al >> filename.txt Write to a file and write over any previous data example: Ls -al > filename.txt
touch - Create file.
touch new.txt - Creates new.txt file with no data touch Documents/rusty.sh - Creates a empty file named rusty.sh in the folder Documents.
rm - Remove File - Delete file
rm rusty.sh - Deletes a file named rusty.sh rm Documents/rusty.sh - Deletes a file named rusty.sh in the folder Documents.
cp - Copy-Paste Copy file
cp rusty.txt rusty2.txt - Copies the file rusty.txt and creates rusty2.txt with all attributes.
mv - Move File
mv rusty2.txt Documents - Move the file named rusty2.txt to the Documents folder.
cat - Display content of file.
cat new.txt
echo - Display text on Screen or Move text to file.
echo "Hello World" - Display Hello World on screen echo My name is Rusty >> new.txt - Writes My name is Rusty into the file new.txt
chmod - To make a file executable.
chmod 777 rusty.sh - Makes rusty.sh Executable and Readable. chmod u+x rusty.sh - Add execute permission for the owner of the file rusty.sh.
chown - Changes the user and/or group that owns a file
sudo chown pi:root rusty.txt pi:root
head - Displays the beginning of a file
head -n 5 filename.txt Display the first 5 lines of file head -c 5 filename.txt Specify the number of bytes.
tail - Displays the end of a file.
tail -n 10 filename.txt Display the last 10 lines of file
alias - This command creates an alias
alias cls='clear'- Alias to clear screen alias ll='ls -al'- Alias 'ls' to change the default action of ls alias rm='rm -i' - Alias to prevent accidental deletion
aspell - Command line Spell checker
aspell check sample.txt
Write to a file and append to it each time example: Ls -al >> filename.txt Write to a file and write over any previous data example: Ls -al > filename.txt
User Commands and user information
Add User Create a new user using useradd or adduser:
sudo useradd -m (username) = user sudo useradd -m (username) -G sudo = administrator sudo adduser username
Users add Groups
sudo adduser username dialout sudo adduser username sudo sudo adduser username adm Groups for pi - pi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio lpadmin groups pi Show groups for user pi groups rusty Show groups for user rusty
Remove Groups
sudo deluser rusty adm - Removes rusty from adm group.
Remove User Delete a user
sudo userdel rusty - Delete user rusty sudo rm -rf /home/rusty - Remove the home directory of the user sudo userdel -r rusty - Delete user rusty and home folder. tail -1 /etc/passwd - Verify user
passwd Create/Change a user password
sudo passwd (username) sudo passwd rusty (Enter current) UNIX password Enter new UNIX password Retype new UNIX password
switch user
sudo /bin/su - root su - Changes user to root user (password needed for root) su rusty - Changes user to rusty (password needed for rusty)
last - Show a listing of last logged in users.
last -a - Display hostnames in the last column last – F - Print full login and logout times last – i - Display IP numbers in numbers-and-dots notation
users user that are loged in
who - who is loged in and when
who -a All options who -b Last boot who -m From where they are loged in who -q All users #users who -r Runlevel who --version Output version
whoami- print effective userid
Basic Terminal Commands
history - Linux store any command you type in an archive file.
history -c - clear all the history history -r - Read in the contents of the file history -w - Overwrites the history file history -d123 - Delete line 123 HISTCONTROL=erasedups