Changes

How Do I: A Linux Q&A

10,495 bytes added, 16 February
The following lines were added (+) and removed (-):
''<small>note: This started over 20 years ago as a simple text file on a BBS. Please forgive some formatting...</small>''== [FORCE EJECT DVD / CDROM DISC] ==-------------------------------------------------------------------------------Determine where it is mounted using the 'df' command then, not against the dev but the mountpoint issue the following: sudo fuser -km /media/label== [PARTITION AND FORMAT LINUX HARD DISK] ==-------------------------------------------------------------------------------Format a hard drive / hard disk / harddrive harddisk from the linux command line.  You cannot edit the partition table if mounted. Using fdisk and knowing the disk device ID (for example we will partition a second harddrive that is /dev/sdb sudo fdisk /dev/sdbYou're in the fdisk interface, select:* press 'p' to show the partition table, do this and make sure that you are using the correct partition (remember sdb is just our example)* press 'n' to create a partition, follow prompts.  The first partition or if there is only one should be made primary.  If you press ENTER though the defaults you will create one large partition using most of the drive.  * press 'w' to write the changes to disk.  You've not created the partition until you write.Now to format the new partition.  For this example we will format as the most common linux type as of this writing (updated for ext4) sudo mkfs.ext4 /dev/sdb1Or if you wish to make a swap partition sudo mkswap /dev/sdb2&nbsp;== [RESUME A STOPPED JOB IN LINUX] ==-------------------------------------------------------------------------------If you see [1]+  Stopped at the console you've stopped a process and placed it in the background.  You may have accidentally pressed Ctrl+Z or you intentionally stopped the process job and now you wish to resume it.type: fgYou can add the job number behind the fg command, if there is only one job it will be job 1 and default to that job.  Learn more about [[Job Management in Linux]].== [SET DATE TIME COMMAND LINE CONSOLE] ==The format date --set="STRING"Set date from the command line date +%Y%m%d -s "20120418"Set time from the command line date +%T -s "11:14:00"== [HOWTO EXTRACT xz / tgz FILE IN LINUX] ==The xz format is a single-file compression format that is based on the LZMA2 algorithm.  Requires xz toos.  Mint/Ubuntu install sudo apt install xz-utilsextract/unzip xz tar file tar -xvf userfiles.tar.xzArchive types tar.gz and tar.xz are both compressed tar-files, however, using variations on the compression method.  For the user there is no difference when extracting either type of file, with the exception of extraction speed.  The compression method for xz produces a more densely compact file resulting in a higher level of compression at the expense of speed.  It may take longer, or even significantly longer to extract files from a xz archive.== [HOWTO COMPRESS with tar zip tar.gz tgz] ==Back up a directory of files and preserve the path.  tar -zcvf sourcefiles archive.tar.gz* -z compress using zip* -c create* -v verbose* -f archive file to createYou can add -p to preserve absolute names, so that the path will begin with the root / and all the way to the directory location.  This is really only useful for doing backups/==[SET PATH VARIABLE SHOW PATH VARIABLE]=={{:Linux Shell Environment Path}}== [HOWTO EXTRACT xz FILE IN LINUX] ==The xz format is a single-file compression format that is based on the LZMA2 algorithm.  Requires xz toos.  Mint/Ubuntu install sudo apt install xz-utilsextract/unzip xz tar file tar -xvf userfiles.tar.xzUsing --max-depth= controls how many subdirectory levels du will display in the listing.  Each level still includes an estimation including all depth of subdirectory however the total is combined without the need for showing greater depth into the directory tree than what is specified by this parameter.  In our example du will list only the first directory layer and the sizes including contents.  The total space consumption for the current directory tree will also be reported. du -BM --max-depth=1 | sort -nrsorted largest first== [DETERMINE LINUX VERSION KERNEL VERSION OR DISTRIBUTION VERSION] ==See: [[Determining Your Linux Version]] == [COMPARE FILES IN LINUX] ==There are a number of tools to accomplish this.  Tools for binary files and for text files, and a combination of the two exist.  Common examples:*cmp - compare two files byte by byte*diff - compare files line by linecmp' reports the differences between two files character by character, instead of line by line. As a result, it is more useful than 'diff' for comparing binary files. For text files, 'cmp' is useful mainly when you want to know only whether two files are identical.*comm - compare two sorted files line by lineOther commands: dircmp, uniq, ...In an example, lets compare two files without regards to binary or text, just to determine if identical. cmp file1 file2Compares file1 to file2, reading each file byte-by-byte and comparing them until one of the byte pairs is not equal. When a difference is found, it will output the location in the file where the difference was found, and exit.  By default, `cmp' outputs nothing if the two files have the same contents.  If one file is a prefix of the other, `cmp' prints to standard error a message.== [LIST FILES IN FOLDER BASED ON DATE RANGE OR NEWER / OLDER THAN] ==Some related searches: linux list files modified after date and linux list files for a specific date range.  This is not a task best suited for the 'ls' command.  Instead, we defer to the '[[Find_and_Locate|find]]' command.You can use the find command to find all files that have been modified after a certain number of days. For example, to find all files in the current directory that have been modified since yesterday (24 hours ago) use: find . -maxdepth 1 -mtime -1Note that to find files modified before 24 hours ago, you have to use -mtime +1 instead of -mtime -1. find . -type f -newermt '1/30/2017 0:00:00'This will find all files modified after a specific date.A range: m  The modification time of the file reference t  reference is interpreted directly as a timetry find . -type f -newermt 20111222 \! -newermt 20111225note that you can directly specify your dates: find -type f -newermt "2011-12-22" \! -newermt "2011-12-24"or find -type f -newermt "2011-12-22 00:00:00" \! -newermt "2011-12-24 13:23:00"if you additionally want to specify the time. find . -mindepth 1 -maxdepth 1 -mtime -7  find . -type f -newermt '11/25/2020 0:00:00'If you don't limit the search to files when it finds a matching directory it will list every file within it.  Be sure to use the "-type f" for files. find . -type f -mtime -30Now with some fancy formatting find . -type f -mtime -30 -printf "%M %u %g %TR %TD %p\n"Last, this working example was used to check a public share on a file server and generate a report, showing only files modified after the specific date. find . -type f -newermt '11/25/2020 0:00:00' > ~/public-drive-newer.txt== [TEST IF PORT IS OPEN, CONNECT TO PORT FROM CLIENT (with netcat) ] ==On system A you may want to connect to system B via a specific software that uses a specific port.  You may also be trying to diagnose a connection issue.  For example, say you want to know if port 6000 is open, as in not blocked on the remote system then you do a test with netcat.  The netcat command is simply 'nc'.  On the remote host type: nc -l 6000Now netcat is listening on port 6000On the local host you can simply use telnet to send text. telnet remote-ip 6000Once connected type some characters and see if they appear on the remote.  If no connection then you are blocked or remote is not listening.  Otherwise you will see your text echo'd on the remote.== [MEASURE THE STRENGTH OF WIFI CONNECTION] ==To measure the strength of the wireless connection from CLI watch -n1 iwconfigShows link quality as well as signal level.== [DISPLAY RESOLUTIONS AVAILABLE FOR MONITOR OR SET FROM COMMAND LINE] ==Use the xrandr command.  Xrandr is used to set the size, orientation and/or reflection of the outputs for a screen. It can also set the screen size.If you type 'xrandr' and ENTER you will see info about your current display.  See if you are using something like VGA-1, DVI-0, HDMI-1, DP-1, etc etc <- examples onlyDO NOT TYPE: xgamma --output VGA-1 --brightness 0 (substitute VGA-1) for your display, this will make your screen black and you will see nothing.  Here is a working example: xrandr --output VGA-1 --brightness 0.75Learn more man xrandr== [ADJUST DISPLAY CONTRAST AND TINT FROM COMMAND LINE] ==You can [[Adjust the Display With xgamma and xrandr]] from the command line.  See xrandr above. xrandr --output VGA-1 --gamma 1:1:1Use the xgamma command.  A gamma value of 1.0 is the default.  A gamma value of 0.8 would give you more contrast.  A value of 1.4 would be much less contrast.  Example usage: xgamma -gamma 0.8xgamma - Alter a monitor's gamma correction through the X server.  The gamma correction can either be defined as a single value, or separately for the red, green and blue components.  Also: -rgamma -ggamma -bgammaLearn more man xgamma== [MONITOR USB PORTS FOR CONNECTING OR DISCONNECTING] ==udevadm real-time monitoring of usb ports: To see if a device is plugged into USB or unplugged, real time monitoring showing when a USB device is connected or disconnected. udevadm monitor --subsystem-match=usbDoes not require sudoAs soon as you connect any USB device, be it a USB flash drive or USB keyboard, mouse, etc details will be displayed.  Also when disconnected.== [CLI SHELL AUTO COMPLETE COMMAND LINE PATH NO LONGER CYCLES] ==This is actually a readline feature called menu-complete . You can bind it to tab (replacing the default complete) by running: bind TAB:menu-completeYou probably want to add that to your ~/.bashrc. Alternatively, you could configure it for all readline completions (not just bash) in ~/.inputrc.You may also find bind -p (show current bindings, note that shows tab as "\C-i") and bind -l (list all functions that can be bound) useful, as well as the bash manual's line editing section and readline's documentation.  source: [https://unix.stackexchange.com/questions/24419/terminal-autocomplete-cycle-through-suggestions derobert on stackexchange][[Category:How_Do_I_Series]]
Bureaucrat, administrator
16,195
edits