Ubuntu Command
unpublished draft
LinuxDebianUbuntu
Linux overview#
Many other distribution on many bases was publication. But I mostly focus on:
RPM-based:
- Use .rpm file format
- Represent:
- CentOs <- Redhat enterprise Linux
- Fedora
- openSUSE
- apt-rpm
- ....
Debian-based:
- Emphasizes free software.
- .deb package format and the dpkg package manager and its frontends (such as apt or synaptic).
- Represent:
- Ubuntu (version xx.04 are LTS)
- Debian
- Basically
deb
file was prettumuch equivalent tomsi
setup file. And instead of double click to install, we do command linesudo apt install [path to the file]
LINUX DEBIAN BASED
File Structure:
- /bin: Binary files for single user
- /sbin: [System Binary files] Binary files for multiple users (for all users sessions mode).
- /boot: Linux image and boot configurations files
- /dev: pseudo files representing devices (such as mouse, keyboard, printer,...)
- /etc: configuration files use be system
- /home: user's files
- /lib: software library dependencies
- /root: root user's files
- /usr: non-essential addition binaries
- /var: files that would be update frequently (logs, application data, cache,...)
Pseudo files directories: Files that got dynamic generated, not persistence, by system boot or some event.
- /proc: Files representing running system processes
- /dev: as upper section
- /sys: Data on system and kernel resources
Create window usb installation#
- Using WoeUSB, download bash file as tutorial
- Install wimtools via
sudo apt-get install wimtools
- Plugin USB, find device by
sudo fdisk -l
- Run the script, e.g.
sudo ./woeusb-5.2.4.bash -d ./Win11_English_x64v1.iso /dev/sda
Shortcut#
Ctrl+Alt+T
: Open terminalCtrl+H
: Show/hide hidden files
Command#
Woking with system#
- Listing what packages are installed on Ubuntu Linux
landscape
: Show useful current status of machine (SysInfo: each integer represent approximately 1 CPU full run)sudo setfacl -R -m u:[UserName] :rwx /app
- setfacl: Sets Access Control Lists (ACLs) of files and directories.
- R: Recursive
- m: Modify
- rwx: read write exucute permission
- /app: directory
chmod
: The command sets the file permissions flags on a file or folder. The flags define who can read, write to or execute the file. r: read - w: write - x: execute -R: recursive -m: modify +x: add executable type to the file, usually the .sh filessudo ufw status
: firewall status of machinewhich [binary]
: trace the binary location in the system file structuresudo apt install [things we want to install]
- sudo apt install nginx:install nginx
apt
: ubuntu package management, equivalent to npm of node and maven of java.apt
is basically a tool merges functionalities ofapt-get
andapt-cache
. Favorapt
over the other two if possible.
systemctl status [process name]
: Get process informationsudo systemctl start [service file]
: Execute the service filesudo systemctl stop nginx
: stop nginxsudo apt purge nginx
sudo apt-get autoremove
sudo systemctl deamon-reload
sudo systemctl restart nginx
User and Group#
sudo useradd -m [userName]
: -m create a folder in home tree directory with the user's namesudo passwd [userName]
: change specific user passwordsud groupadd [groupName]
: create a new user groupsudo chown :[groupName] [absolutePath]
: grant owner permission to user group following the absotule pathsudo usermod -a -G [groupName] [userName]
: Modify user permission-a
: add-G
: Existing group, normally followed by group name and user name
sudo chmod g+w [absolutePath]
: Add write permission of the [absolutePath] to the user group.
File Manage#
du
: Check how much space a file or a directory takes(Disk Usage).df
: Shows the size, used space, and available space on the mounted filesystems of your computer.find
: Track down files that you know exist if you can’t remember where you put them.locate
: Locate a file, just like the search command in Windows.ls
: It lists the files and folders in the directory you specify. By default, ls looks in the current directory.-a
: All, include hidden files
pwd
: Prints the working directory (the current directory) from the root / directory.mkdir
: Allows you to create new directories in the filesystem. You must provide the name of the new directory to mkdir.cp
: Use the cp command to copy files from the current directory to a different directory.mv
: Allows you to move files and directories from directory to directory. It also allows you to rename files.rm
: Delete directories and the contents within them.tar
: Create an archive file (also called a tarball) that can contain many other files. This makes it much more convenient to distribute a collection of files.zip
, unzip: Use the zip command to compress your files into a zip archive, and use the unzip command to extract the zipped files from a zip archive.gzip
: Compresses files.
File Interactive#
cat
: Concatenate lists the contents of files to the terminal window. This is faster than opening the file in an editor, and there’s no chance you can accidentally alter the filediff
: Compares two text files and shows the differences between them.grep
: Searches for lines which contain a search pattern. Could be consider as small version of regex.head
: Gives you a listing of the first 10 lines of a file. If you want to see fewer or more lines, use the -n (number) option.tail
: Gives you a listing of the last 10 lines of a file.less
: Allows you to view files without opening an editor. It’s faster to use, and there’s no chance of you inadvertently modifying the filetouch
: create a file
Common Operations#
echo
: Prints (echoes) a string of text to the terminal window.man
: The man command displays the “man pages” for a command in less . The man pages are the user manual for that command.history
: Lists the commands you have previously issued on the command line.ps
: Lists running processesfree
: Gives you a summary of the memory usage with your computer. It does this for both the main Random Access Memory (RAM) and swap memory. -h: human is used to provide human-friendly numbers and unitstop
: Shows a real-time display of the data relating to your Linux machine. The top of the screen is a status summary. Press the Q key to exit from top.uname
: Obtain some system information regarding the Linux computer you’re working on.hostname
: know the name of your host/network.jobs
: Display all current jobs along with their statuses. A job is basically a process that is started by the shell.shutdown
: Shut down or reboot your Linux system. Using with no parameters will shut down your computer in one minute.exit
: Close a terminal window, end the execution of a shell script, or log you out of an SSH remote access session.ssh
: Make a connection to a remote Linux computer and log into your account.cd
: The cd command changes your current directory. In other words, it moves you to a new place in the filesystem.sudo
: Required when performing actions that require root or superuser permissions, such as changing the password for another user.whoami
: Find out who you are logged in as or who is logged into an unmanned Linux terminal.w
: Lists the currently logged in users.apt-get
: Command used to install and update packages - Favorapt
more over if possible.finger
: Gives you a short dump of information about a user, including the time of the user’s last login, the user’s home directory, and the user account’s full name.groups
: Tells you which groups a user is a member of.useradd
: To create a new user.userdel
: To delete the users account.passwd
: Lets you change the password for a user. Just type passwd to change your own password.chown
: Allows you to change the owner and group owner of a file.kill
: The kill command allows you to terminate a process from the command line. You do this by providing the process ID (PID) of the process to kill.wget
: Download files from the internet.
Un-classified command#
man [name of command]
: provide user manual of the specific command.- #![absoluteAddressToTheBinaryFile]: Tell linux the file is the executable script, and will run base on the Binary File.
Install SSH#
- On server:
apt install openssh-server
- On client:
apt install openssh-client
- /etc/ssh:
- sshd_config: edit system host behavior
- ssh_config: handle the way your system will login as a client on remote hosts
ssh [user]@[serverIpAddress]
- user: the user we want to use to login when use ssh
- serverIpAddress: Ip of the server we want to connect
scp [localfile] [user]@[serverIpAddress]:[absolutePathOnTheServer]
: securely copy a file from local machine to the server
Common Parameters#
-a
: All-l
: long form-h
: human readable format-t
: order by descending chronological orderxzf
: Extract zip fileczf
: Compress zip file
Furthur investigation#
systemd
- Many options that can pass-in when run an asp.net core application. Sample:
dotnet [appName].dll --url http://*:5000
(run appName, Kestrel listen http on port 5000) ip addr
: Show network informationnetstat
-ant: trace network currently running -l: Listing all listsening porthost
[domain website name]: give the public ipaddress of the siteetc/hosts
: the place you can config your own ip-mapping on the machine
Common task#
Run a script at boot-time#
Barebone rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
exit 0
- The commands are run under root user.
- Place commands above the line that says
exit 0
. - Make it executable by
chmod +x /etc/rc.local
. - If the file is not exists yet, create it
nano /etc/rc.local
.