Repository navigation
Linux
- Commands and Utilities
- System Information
- Networking
- User Management
- Services and their configs
- VMware Virtualization
-
Others
- Merge several files into one
- Remove packet including its config files
- View total directory size or single file size
- File content output without comments
- Find files matching specified name
- Find files which containing specific string
- Change permissions only on files
- Applying action on service when interface event has happened
- Measuring command time execution
- Add Full-HD resolution on VM linux
Next command will print out a list of installed packages: sudo apt list --installed.
Source: askubuntu.com
To make an image of data, stored on hard drive, next command must be used:
sudo dd if=<Source hard drive> conv=sync,noerror bs=64K status=progress | gzip -c > <Path to image file>.
Where:
-
<Source hard drive>– path to the hard drive, that will be backuped (for examle,/dev/sda); -
<Path to image file>– path to the result file, which will contain data (like/media/user/usb/backup.img.gz).
To restore data to selected hard drive from a backup file, use this command:
gunzip -c <Path to image file> | sudo dd of=<Target hard drive> status=progress.
Where:
-
<Path to image file>– path to the file, which contains an reserve copy of the data (like/media/user/usb/backup.img.gz); -
<Target hard drive>– path to the hard drive, which will be overwritten with restored data (for examle,/dev/sda).
Source: linux.com
Next command will create all folders in specified path even ever they are not exist: mkdir -p <Path to directory>.
Access mode can be assigned to the newly created directories using -m key: mkdir -p <Permission bits> <Path to directory>.
Where:
-
<Path to directory>– full path to the newly created directory (like, I know.../tmp/super-secret-folder); -
<Permission bits>– linux permission bits in numeric format (like0755or644).
Source: linux.die.net
For creating a new screen with human-readable name use: screen -S '<Screen name>' <Command> command.
Source: stackoverflow.com
For executing command from name of another user use: su <Username> -c "<Command>" command.
Source: stackexchange.com
Running ffserver command: ffserver -f <Config file>.
Where:
-
<Config file>– ffserver configuration file (/etc/ffserver.confby default).
Launching ffmpeg stream:
ffmpeg -f <Format selecting> -s <Resolution selecting> -framerate <FPS> -pixel_format <Pixel format> -i <Input source> <Output destination>.
Where:
-
<Format selecting>– format type (video4linux2is suitable); -
<Resolution selecting>– source resolution selecting (like640x480or another supported one); -
<FPS>– source frames per second value that's needed (simple number like30); -
<Pixel format>– pixel format, that will be used (yuyv422is good choice); -
<Input source>– selecting input source (/dev/video0by default for video streaming from single web-cam); -
<Output destination>– selecting output destination (http://<Host name>:<Port>/<Feed name>for streaming, where:-
<Host name>– host name or IP address of the streaming host (localhostis good choice!); -
<Port>– selected port for the streaming server (from the/etc/ffserver.conffile,8090by default); -
<Feed name>– name of the configured feed (from the/etc/ffserver.conffile,feed1.ffmby default).
-
Sources: acmesystems.it, github.com
For copying files recursivelly from local machine to remote SMB server use next command:
smbclient //<Remote SMB server address> -U <Username> -c 'prompt OFF; recurse ON; cd <Remote directory>; lcd <Local directory>; mput *'.
Source: stackoverflow.com
For repeating specified command every X seconds you can use next construction:
watch -n X <Command with arguments>.
Source: tecmint.com
This command will show-off all technical information about installed CPU: lscpu.
Source: linux.die.net
To view all partitions just use: sudo fdisk -l.
Also, lsblk command can be used.
Source: linux.die.net
To show S.M.A.R.T. capabilities of the device: sudo smartctl -c <Disk name>.
To show S.M.A.R.T. status of the device: sudo smartctl -H <Disk name>.
To show all S.M.A.R.T. information of the device: sudo smartctl -a <Disk name>.
Where:
-
<Disk name>– disk name (like/dev/sda).
Source: linux.die.net
To check all running services, that are listening on TCP and UDP ports, this command will be useful:
netstat -lntu. Flags, that can be used:
-
-l– show only services which are listening on some port; -
-n– show port number (don't try to resolve the service name); -
-t– include TCP ports; -
-u– include UDP ports; -
-p– include name of the program.
Source: superuser.com
To list all of existing local users in the system this command will be useful:
cut -d: -f1 /etc/passwd.
Source: askubuntu.com
To add an existing user to an existing secondary group must use this command:
usermod -a -G <Group name> <User name>.
Source: linux.die.net
| Service | Packet name | Config files | Service file |
|---|---|---|---|
| SAMBA | samba | /etc/samba/smb.conf | /etc/init.d/samba |
| TFTP | tftpd-hpa | /etc/default/tftpd-hpa | /etc/init.d/tftpd-hpa |
| /etc/tftpd.remap | |||
| NFS | nfs-kernel-server | /etc/exports | /etc/init.d/nfs-kernel-server |
| nfs-common |
VMware Tools can be installed in two ways:
- from CD disc, using vSphere or Workstation clients;
- from repository, using command
sudo apt-get install open-vm-tools.
Source: vmware.com, kb.vmware.com
Next command can be used to merge several files into single one:
cat <Path to source files> > <Path to result file>
Where:
-
<Path to source files>– can contain file type mask (like*.txt); -
<Path to result file>– output file name or path to it.
Source: stackexchange.com
To remove installed packet with configuration files, associated with it, next command will be helpful: sudo apt-get purge <Package name>.
Source: askubuntu.com
For viewing total directory size or single file size in human-readable format, just use command:
du -sh <Path to directory or file>
For filtering items by size with limitation by directory level can be used next command:
du -h --threshold=<Size> --max-depth=<Depth> <Path to directory or file>
Where:
-
<Size>– limit size (K,M,Gand others postfixes are accepted); -
<Depth>– max level of scanning (simple number, e.g.1,2,3).
Source: stackexchange.com
Next command will execute file content output without comments:
cat <Path to file> | egrep -v "^\s*(#|$)".
Source: kvz.io
For searching for files with known name find <Search directory> -name <Needed file name> command can be used.
Source: codecoffee.com
For searching for files which containing specific string, just use command:
grep -rnw <Search directory> -e <Specific string>.
Source: stackoverflow.com
For changing permissions only on files in selected directory, next command can be used:
find <Path to the directory> -type f | sudo xargs chmod <Permissions as octal value>.
Source: askubuntu.com
To assign an action on event, generated by selected networking interface, simple script, placed in /etc/network/<Event type> location can be used.
Where:
-
<Event type>– Directory name, associated with event type:-
if-down.d– directory for scripts, applying when interface is going down; -
if-post-down.d– directory for scripts, applying after interface going down event; -
if-pre-up.d– directory for scripts, applying before interface going up event; -
if-up.d– directory for scripts, applying when interface is going up.
-
Script example listed below:
#!/bin/sh
if [ "$IFACE" = <Interface name> ]; then
<Required action>
fi
exit 0
Source: askubuntu.com
To measure execution time of command or program command time can be used:
time <command>.
Source: stackoverflow.com
To add the Full-HD resolution on linux machine, that's running in virtual environment, use next commands from the list bellow.
Before using them please refer to the manual on source link and validate proper names of devices and modes for your installation.
gtf 1920 1080 60
xrandr --newmode "1920x1080_60.00" 172.80 1920 2040 2248 2576 1080 1081 1084 1118 -HSync +Vsync
xrandr --addmode Virtual1 "1920x1080_60.00"
xrandr --output Virtual1 --mode "1920x1080_60.00"
Source: stackexchange.com