This repository was archived by the owner on Jul 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Useful Linux
Dylan Christopherson edited this page Jul 12, 2018
·
49 revisions
Useful Linux Commands!
Use with care
sudo -s
Important info
ethtool -P eth0 //MAC address (Permanent address)
hostname
hostname -I
uname -m //Kernel information
uname -s
uname -r
cat /etc/os-release
Managing users
useradd <user>
passwd <user>
userdel <user> //Only deletes users account
userdel -r <user> //Removes user, home folder, and their files
getent group wheel
usermod -aG wheel <user>
su - <user> //Switch users
Directories
rm -r -f <directory> //Removes all files from directory
cp -a /source/. /dest/ //-a preserves all file attribures and symlinks
//. at the end allows to copy all files and folders including hidden ones
chown -R username:groupname * Ex: chown -R jenkins:users * //changes all ownership in file
cd - //Changes directory to previous working directory
List Stuff
ls -d */ //List directories in a directory
Adding to Path
echo $PATH
PATH=$PATH:<Directory path>
export PATH
export PATH=$PATH:<Directory path> //All in one command
echo 'PATH=$PATH:/opt/openmpi/bin' >> /etc/bashrc //Another way to add path
Symlinks
ln -s /full/path/to/file /full/path/to/link/area
Ex: ln -s /home/dylan/aws-pmix/mysqlauth.sh /home/dylan/aws-pmix/backend/shared/mysqlauth.sh
ls -Al //In directory you created symlink. Should look something like this:
lrwxrwxrwx 1 dylan users 47 Jun 12 12:02 mysqlauth.sh -> /home/dylan/aws-pmix-scale-testing/mysqlauth.sh
The arrow pointing to the file path is the symlink. To delete a symlink, go into the directory with the symlink and:
rm fileName
Ex: rm mysqlauth.sh
Figure out what stuff is
type <command> //Tells you what type of command it is
file <filename> //Tells you what type of file it is
printenv | less //Prints environment variables
Date
date
time
https://stackoverflow.com/questions/21721875/store-date-variable-in-bash-script
Less Command
Page Up or b Scroll back one page
Page Down or space Scroll forward one page
Up Arrow Scroll up one line
Down Arrow Scroll down one line
G Move to the end of the text file
1G or g Move to the beginning of the text file
/_characters_ Search forward to the next occurrence of _characters_
?_characters_ Search backward to the next occurrence of _characters_
n Search for the next occurrence of the previous search
h Display help screen
q Quit less
Directories in Linux
Under "3-Exploring The System" in The Linux Command Line book
/ The root directory. Where everything begins.
/bin Contains binaries (programs) that be must present for the system to boot and run
/boot
/dev This is a special directory which contains device nodes. “Everything is a file” also applies to devices. Here is where the kernel maintains a list of all the devices it understands.
/etc
/home
/lib Contains shared library files used by the core system programs. These are similar to DLLs in Windows.
/lost+found
/media
/mnt
/opt
/proc
/root
/sbin
/tmp
/usr
/usr/bin
/usr/lib
/usr/local
/usr/sbin
/usr/share
/usr/share/doc
/var
/var/log