Basic Linux User, System, and Package Commands
A compact command reference for Linux users, permissions, system information, package management, and Vim.
Logged-in users and groups
Show the current user
$ whoamiOr:
$ id -unShow the current user and TTY
$ who am iShow the current user’s identity and groups
$ idShow command history
$ historyShow users who have logged in before
The last command displays a particular user’s login history. Without arguments, it displays the history for all users. By default, the information comes from /var/log/wtmp.
$ last usernameSwitch users
$ su usernameAdd or change a user’s password
$ sudo passwd usernameEnter the new password when prompted to set the password for username.
File permissions
Change read and write permissions
chmod [-cfvR] [--help] [--version] mode file1 file2
mode is a permission string in the form ugoa...:
uis the file owner,gis users in the owner’s group,ois everyone else, andameans all three.+adds permission,-removes it, and=sets the exact permissions.rmeans readable,wwritable,xexecutable, andXexecutable only when the file is a directory or already has an execute bit.-Rapplies the change recursively.
For example, add execute permission to a file:
$ sudo chmod +x fileChange a file’s owner or group
-Rrecursively changes the owner of a directory and all files and subdirectories beneath it.-vdisplays the work performed bychown.
For example, change the owner and group of dirname from root to bico:
$ sudo chown -R bico:bico dirnamePackage management
Ubuntu has a useful official Chinese package-management guide, which I strongly recommend. Additional references cover tools including Yum:
Reference 1
Reference 2
Reference 3
Vim
Force-save a file opened without root privileges
:w !sudo tee %