Last active
July 25, 2025 14:15
-
-
Save githubfoam/377bebf31400b81c846a90a9792e20f2 to your computer and use it in GitHub Desktop.
Revisions
-
githubfoam revised this gist
Mar 11, 2025 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1437,6 +1437,10 @@ Alternatively, check with: service cron status Now restart cron and check logs: service cron restart tail -f /var/log/ansible-cron.log #php specific php /bla/bla/something.php >> /var/logs/somelog-for-stdout.log -
githubfoam revised this gist
Mar 11, 2025 . 1 changed file with 23 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1415,6 +1415,29 @@ $ cat /etc/cron.d/barak_job */1 * * * * barak echo "Nightly Backup Successful: $(date) " &> /tmp/test1_job.log #redirect stdout and stderr to a file. */1 * * * * barak echo "Nightly Backup Successful: $(date) " > /tmp/test1_job.log2 2>&1 #redirect stdout and stderr to a file. Start the Cron Service Once installed, start the cron daemon: service cron start OR, run it in the foreground: cron -f & Verify that the cron service is active: ps aux | grep cron Expected output should include a running cron process: root 12 0.0 0.0 1856 652 ? Ss 12:34 0:00 /usr/sbin/cron -f Alternatively, check with: service cron status #php specific php /bla/bla/something.php >> /var/logs/somelog-for-stdout.log #the only difference from the syntax of the user crontabs is that the line specifies the user to run the job as -
githubfoam revised this gist
Mar 10, 2025 . 1 changed file with 53 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5228,6 +5228,59 @@ $ sudo shutdown -c #Cancel a timed shutdown $ sudo shutdown -r now #restarting the system $ sudo systemctl reboot #restarting the system ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Verify the Exact Filename Use the following command to list files in a way that reveals hidden characters: ls -b This will show special characters in an escaped format. For example, if the filename contains unexpected characters (like spaces or newlines), ls -b will display them. Step 2: Delete the File Method 1: Use Quotation Marks rm '{' or rm "{" Method 2: Use an Escape Character (\) rm \{ Method 3: Use -- to Prevent Option Parsing rm -- { Method 4: Using Inode Number (Safest) Find the inode number of the file: ls -li Example output: 1234567 { Delete the file using find: find . -inum 1234567 -delete Final Check Run ls again to confirm that the file is deleted. If you still see it, double-check hidden characters using: ls -bQ If necessary, copy the exact filename and delete it using: rm -- "PASTE_FILENAME_HERE" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ #how to delete file with inode find . -inum 1847 -ls find . -inum 1847 -exec rm {} \; -
githubfoam revised this gist
Feb 12, 2025 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5253,4 +5253,23 @@ exec bash #Listing a Directory with Spaces ls "My Documents" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ # check if a URL works (i.e., is reachable and responding) from the command line If the URL works, it will return an HTTP status, such as 200 OK. If the URL is broken, it may return 404 Not Found or 500 Internal Server Error. curl -Is https://example.com | head -n 1 wget --spider -S https://example.com 2>&1 | grep "HTTP/" ping -c 4 example.com nc -zv example.com 443 nc -zv example.com 443 telnet example.com 80 dig example.com +short curl -L <URL> #Retrieve full content (optional) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -
githubfoam revised this gist
Dec 27, 2024 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2903,6 +2903,8 @@ $ find . -type f -exec ls -s {} + | sort -n -r | head -3 #Find first 3 largest f $ find /etc/ -type f -exec ls -s {} + | sort -n | head -3 #Find first 3 smallest files located in a in a current directory recursively $ find . -type f -size 0b # search for empty files $ find . -type f -empty # search for empty files $ find . -empty # search for empty files or folders $ sudo find /var/log -name \*.log -size +1M -exec ls -lrt {} \; # find files larger than 1M,`M' for Megabytes (units of 1048576 bytes) $ sudo find /var/log -name \*.log -size +1M -exec ls -lrt {} \; | wc -l #get count -
githubfoam revised this gist
Feb 1, 2024 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5247,6 +5247,8 @@ After making changes to the .bashrc file, restart the Bash shell or source the f source ~/.bashrc or exec bash ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ #Listing a Directory with Spaces ls "My Documents" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -
githubfoam revised this gist
Feb 1, 2024 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1959,6 +1959,10 @@ curl -b cookies.txt 'http://forum.ru-board.com/topic.cgi?forum=35&topic=80699&st curl -L -o ds.tar.gz https://downloads.dockerslim.com/releases/1.37.3/dist_linux.tar.gz tar -xvf ds.tar.gz -C /usr/local/bin #uncompress the tar.gz file into a specific folder. tar -xzvf your_file.tar.gz -C /path/to/destination/folder tar xvzf tkn_0.10.0_Darwin_x86_64.tar.gz -C /usr/local/bin tkn tar xjvf backup.tbz tar -zxvf backup.tar.gz -
githubfoam revised this gist
Dec 15, 2023 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5230,4 +5230,19 @@ find . -inum 782263 -exec rm -i {} \; #how to delete directory/folder with inode find . -inum 393232 -delete ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ #The error message you're encountering seems to indicate a problem with the execution or syntax within the .bashrc file. The .bashrc file is a script that runs whenever a new terminal session is started for a user in Bash nano ~/.bashrc If there's no obvious syntax error, try validating the syntax of the .bashrc file using the bash command bash -n ~/.bashrc After making changes to the .bashrc file, restart the Bash shell or source the file to apply the changes source ~/.bashrc or exec bash ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -
githubfoam revised this gist
Sep 22, 2023 . 1 changed file with 0 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1078,14 +1078,6 @@ $ file raw_file.txt #if a text file contains ASCII or Unicode $ file -b symbolic_test1.txt symbolic link to test1.txt ----------------------------------------------------------------------------------------------------- # parse html with curl curl -s https://miloserdov.org/ | grep -E -o '<h3 class=ftitle>.*</h3>' | sed 's/<h3 class=ftitle>//' | sed 's/<\/h3>//' curl http://test.com | sed -rn 's@(^.*<dd>)(.*)(</dd>)@\2@p' -
githubfoam revised this gist
Sep 22, 2023 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1078,6 +1078,14 @@ $ file raw_file.txt #if a text file contains ASCII or Unicode $ file -b symbolic_test1.txt symbolic link to test1.txt ----------------------------------------------------------------------------------------------------- curl -F "file=@path-to-file" http://www.example.com/upload #upload a file curl -H "Authorization: Bearer YOUR_TOKEN" http://www.example.com #Add Headers curl --limit-rate 1M -o http://www.example.com/file.zip #download curl --limit-rate 1M -o -C http://www.example.com/file.zip #resume download curl -x http://proxyserver.com:port http://www.example.com #use proxy curl -k https://www.example.com #skip SSL Certificate Verification curl --cert mycert.pem https://www.example.com #use Certificate ----------------------------------------------------------------------------------------------------- # parse html with curl curl -s https://miloserdov.org/ | grep -E -o '<h3 class=ftitle>.*</h3>' | sed 's/<h3 class=ftitle>//' | sed 's/<\/h3>//' curl http://test.com | sed -rn 's@(^.*<dd>)(.*)(</dd>)@\2@p' -
githubfoam revised this gist
Aug 31, 2023 . 1 changed file with 36 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4358,6 +4358,42 @@ protection from inadvertently overwriting files when copying ~/.bashrc alias cp='cp -i' ------------------------------------------------------------------------------------------ # list tree structure of files and folders $ ls -R .: create_folders_files.sh folder_1 folder_2 folder_3 ./folder_1: file_1.txt file_2.txt file_3.txt file_4.txt ./folder_2: file_1.txt file_2.txt file_3.txt file_4.txt ./folder_3: file_1.txt file_2.txt file_3.txt file_4.txt $ find . . ./folder_2 ./folder_2/file_1.txt ./folder_2/file_2.txt ./folder_2/file_3.txt ./folder_2/file_4.txt ./create_folders_files.sh ./folder_1 ./folder_1/file_1.txt ./folder_1/file_2.txt ./folder_1/file_3.txt ./folder_1/file_4.txt ./folder_3 ./folder_3/file_1.txt ./folder_3/file_2.txt ./folder_3/file_3.txt ./folder_3/file_4.txt $ sudo tree -d /var/log/ --du -sch /var/log/ ├── [4.0K] dist-upgrade -
githubfoam revised this gist
Aug 31, 2023 . 1 changed file with 25 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3024,6 +3024,31 @@ find /var/www -user pedro -name "*.pl" # find all *.pl (perl files) file belongs find / -type f -user bonnie -o -user clyde #find files by users bonnie and clyde find / -type d -user vivek -o -user wendy #find dirs by users bonnie and clyde ---------------------------------------------------------------------------------------------------- #delete multiple folders in a folder which have files in them Run the following command to list the folders that will be affected by the deletion command The output of the find command will display a list of folder names. Carefully review this list to make sure that it includes only the folders you intend to delete find . -type d Once you're satisfied with the list and have made any necessary modifications to exclude specific folders, you can run the original deletion command: find . -type d -exec rm -r {} \; Use the xargs command to pass the output of the find command to the rm command: find . -type d | xargs rm -rf find . -type d -exec rm -r {} \; find .: Searches for files and directories in the current directory and its subdirectories. -type d: Specifies that the search should only include directories (folders). -exec rm -r {} \;: Executes the rm -r command on each found directory. The {} is a placeholder for the found directory name, and \; indicates the end of the -exec command. Be cautious when using this command, as it will delete all directories, including their contents, within the specified directory. find . -type d -exec rm -rf {} \; use the -f option with rm to suppress confirmation prompts and force deletion. However, be cautious with the -f option, as it will delete without asking for confirmation. ---------------------------------------------------------------------------------------------------- find test -type d -name '.git' # list git directories find . -type d -newermt 2012-02-01 ! -newermt 2022-01-01 -ls #list directories between 1st Dec 2021 and 1st Jan 2022 find . -type d -newermt 2012-03-22 ! -newermt 2022-03-24 -exec echo {} \; #test before delete -
githubfoam revised this gist
Aug 26, 2023 . 1 changed file with 39 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -117,6 +117,45 @@ $ bash --version awk -F':' '/sudo/{print $4}' /etc/group grep '^sudo' /etc/group grep -w sudo /etc/group ------------------------------------------------------------------------------------------ #Bard The command [ -f /var/run/reboot-required ] && sudo reboot -f first checks if the file /var/run/reboot-required exists. If it does, the command then runs the sudo reboot -f command, which forcefully reboots the system. The file /var/run/reboot-required is created by some Linux distributions when a system update requires a reboot. This is to ensure that the system is properly updated before it is restarted. The sudo reboot -f command forcefully reboots the system, even if there are unsaved changes in open files. This is useful if the system is unresponsive or if you need to reboot it immediately. Some of the best uses cases for the command [ -f /var/run/reboot-required ] && sudo reboot -f are: After a system update that requires a reboot. If the system is unresponsive. If you need to reboot the system immediately. It is important to note that forcefully rebooting the system can sometimes cause data loss. Therefore, you should only use this command if you are sure that there are no unsaved changes in open files. ------------------------------------------------------------------------------------------ #ChatGPT This command is used in a Linux shell environment and is composed of two parts connected by the && operator. The overall purpose of this command is to check if a specific file exists and, if it does, initiate a system reboot with administrative privileges. Let's break down each part of the command: [ -f /var/run/reboot-required ]: This is a conditional test using the [ (test) command. The -f flag checks if the specified file (/var/run/reboot-required) exists. This file is often used on Ubuntu-based systems to indicate that a system reboot is required due to software updates or configuration changes. &&: This is the logical "AND" operator. It's used to execute the command on the right only if the command on the left (the test in this case) evaluates as true or successful. sudo reboot -f: If the previous test [ -f /var/run/reboot-required ] is successful (meaning the file exists), this command is executed. The sudo command is used to execute the subsequent command with superuser (root) privileges. reboot is a command used to restart the system, and the -f flag forces an immediate reboot without further confirmation. Best Use Cases: Automated Reboot after Updates: This command is commonly used in automated scripts or scheduled tasks, particularly after software updates have been applied to a Linux system. If the file /var/run/reboot-required exists, it suggests that important updates have been installed that require a system restart for them to take effect. By using this command, you can ensure that the system automatically reboots when necessary after updates. Post-Configuration Reboot: In situations where configuration changes are applied that necessitate a reboot, this command can be used to automatically restart the system. For example, if you've made changes that affect kernel modules or critical system services, an automated reboot might be necessary to apply those changes. Server Maintenance and Deployment Scripts: When performing maintenance tasks on servers or during deployment procedures, administrators might use this command to ensure that a system is properly restarted after specific actions are taken. Scripted System Checks: This command can be incorporated into system health-check scripts that are run periodically to ensure the system is in a proper state. If the script detects that a reboot is required, it can automatically initiate one. It's important to exercise caution when using commands that trigger a system reboot, especially in automated scenarios. Rebooting a system without proper planning can lead to unexpected downtime and disruption of services. Always thoroughly test any scripts or commands in a controlled environment before deploying them in production systems. ------------------------------------------------------------------------------------------ "&&" #where the second command is executed only if the exit status of the preceding command is 0 (zero exit code) -
githubfoam revised this gist
Aug 26, 2023 . 1 changed file with 28 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3851,6 +3851,34 @@ cat /etc/group -> List all groups getent group vboxusers groups -> View the Groups a User Account groupmod -g 3000 foo -> assign a new GID to group called foo ------------------------------------------------------------------------------------------ The command you've provided is a Linux shell command that utilizes the cp command to copy files and directories. Let's break down the components of the command: cp: This is the command itself, which stands for "copy." It's used to copy files or directories from one location to another. -vrbi: These are options or flags that modify how the cp command behaves: -v: Stands for "verbose." When this option is used, the cp command will provide more detailed output, showing the names of files as they are copied. -r: Stands for "recursive." This option is used when copying directories. It tells the cp command to copy not only the specified directory but also its contents and subdirectories. -b: Stands for "backup." With this option, the cp command will create backup copies of files that already exist in the destination directory before overwriting them. -i: Stands for "interactive." When this option is used, the cp command will prompt you for confirmation before overwriting files in the destination directory. This is a safety measure to prevent accidental data loss. /etc/skel/.: This is the source directory or file. In this case, it's the .skel directory located in the /etc directory. The /etc/skel directory is often used as a template for creating user home directories. ~/: This is the destination directory. The tilde (~) is a shorthand notation for the user's home directory. So, this part of the command specifies that the copied content should be placed in the user's home directory. The purpose of this command is to copy the contents of the /etc/skel directory (which often contains default settings and configurations for new user accounts) into the user's home directory. It uses various options like -v, -r, -b, and -i to control the copying process and handle situations where files already exist in the destination directory. To automatically answer "yes" to the interactive prompts and proceed with copying without manual confirmation, you can use the yes command in combination with the cp command. The yes command repeatedly outputs the letter "y" (or any other specified character) in response to prompts. Here's an example of how you could use it: sh yes | cp -vrbi /etc/skel/. ~/ In this example, the yes command keeps providing "y" responses to the interactive prompts, effectively saying "yes" to each one. This allows the cp command to copy files without requiring manual confirmation. ------------------------------------------------------------------------------------------ #Files in /etc/skel are copied from this directory to new users’ home directories by certain account-creation tools #The files should be in all new users’ home directories should reside in /etc/skel. -
githubfoam revised this gist
Aug 23, 2023 . 1 changed file with 57 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2015,7 +2015,64 @@ fix: #This is because sudo does not preserve the user's environment variables, including the PATH variable. sudo env "PATH=$PATH" sh -c "go build ." ---------------------------------------------------------------------------------------------------- When you use the "su otheruser" command without the hyphen (-), you switch to the specified user's account, but you inherit the current environment variables and working directory of the original user. This can lead to potential issues if you need the new user's environment to be set up completely. Example Use Cases: If you only need to quickly execute a single command as "otheruser" but do not require the environment to be exactly the same, you might use "su otheruser" to avoid the overhead of starting a new shell session. ┌──(vagrant㉿vg-kali-02)-[~] └─$ su barak Password: ┌──(barak㉿vg-kali-02)-[/home/vagrant] └─$ echo $HOME /home/barak ┌──(barak㉿vg-kali-02)-[/home/vagrant] └─$ pwd /home/vagrant ┌──(barak㉿vg-kali-02)-[/home/vagrant] └─$ exit exit ┌──(vagrant㉿vg-kali-02)-[~] └─$ ---------------------------------------------------------------------------------------------------- When you use the "su - otheruser" command with the hyphen (-), you not only switch to the specified user's account but also start a new shell session with the target user's environment variables and home directory. This ensures a clean environment as if you had logged in directly as that user. In general, you should use su - otheruser if you need to change the shell environment. This is especially important if you are going to be running commands that require specific permissions or settings that are not available in the default shell environmen Example Use Cases: Suppose you are the "originaluser" and you want to run a script that requires specific environment variables and settings of "otheruser." In this case, you would use "su - otheruser" to ensure the script runs with the correct environment. ┌──(vagrant㉿vg-kali-02)-[~] └─$ su - barak Password: ┌──(barak㉿vg-kali-02)-[~] └─$ echo $HOME /home/barak ┌──(barak㉿vg-kali-02)-[~] └─$ pwd /home/barak ┌──(barak㉿vg-kali-02)-[~] └─$ exit logout ┌──(vagrant㉿vg-kali-02)-[~] └─$ ---------------------------------------------------------------------------------------------------- #-H flag makes sudo assume root's home directory as HOME instead of the current user's home directory sudo -H -
githubfoam revised this gist
Aug 23, 2023 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,10 @@ Alt+F: Go right (forward) one word. Ctrl + U to clear up to the beginning Ctrl + U to recall a command by searching history Up Arrow to recall the previous command from history Down Arrow to go to next command in the command history #multiple virtual consoles CTRL + ALT + F1-F8 ------------------------------------------------------------------------------------------------------------------------------------------------- -
githubfoam revised this gist
Jul 21, 2023 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4512,6 +4512,21 @@ D H L P T $ mv error.log{,.OLD} #expands to "mv error.log error.log.OLD") ------------------------------------------------------------------------------------------ #rename multiple files to change the extensions $ mv *.txt *.tsv mv: target 'd.tsv': Not a directory #rename all the files with a .txt extension to .fg extension in the given directory find . -type f -name "*.txt" -exec sh -c 'mv "$1" "${1%.txt}.fg"' _ {} \; #bash script for file in /path/to/directory/*.txt; do mv "$file" "${file%.txt}.fg" done # one liner version of the bash script above find /path/to/directory -type f -name "*.txt" -exec bash -c 'mv "$0" "${0%.txt}.fg"' {} \; ------------------------------------------------------------------------------------------ cmp file1.txt file2.txt #cmp command reports the byte and line number if a difference is found cmp --silent file1 file2 && echo 'SUCCESS: Files Are Identical' || echo 'Files Are Different' cmp --silent $old $new || echo "files are different" -
githubfoam revised this gist
May 26, 2023 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2336,8 +2336,10 @@ $ sudo fuser -n tcp 22 echo $SHELL -> determine current shell type cat /proc/cpuinfo | grep 'vmx\|svm' -> VT-x/AMD-v virtualization is enabled in BIOS # troubleshooting nginx journalctl -u nginx.service tail -n 50 /var/log/nginx/error.log tail -n 50 //var/log/nginx/access.log nginx -t sudo ss -tulpn # Verify that port 80 or 443 curl -I http://10.21.136.13 -
githubfoam revised this gist
Apr 17, 2023 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3066,7 +3066,13 @@ grep -E '[[:digit:]]{3,9}' file.txt #matches all integers that have between 3 an grep 'word' filename grep 'word' file1 file2 file3 grep -i "boar" /etc/passwd #Perform a case-insensitive search for the word ‘bar’ "grep -R 'httpd' ." #Look for all files in the current directory and in all of its subdirectories # search for a keyword in text files within a folder and its subfolders. grep -r "keyword" /path/to/directory grep -r "keyword" --include "*.txt" /path/to/directory # search for a keyword in a specific type of file grep -r -i "keyword" /path/to/directory #case-sensitive when searching for keywords grep -r "192.168.1.5" /etc/ #search recursively i.e. read all files under each directory for a string “192.168.1.5” grep -c 'nixcraft' frontpage.md #display the total number of times that the string ‘nixcraft’ appears in a file named frontpage.md -
githubfoam revised this gist
Apr 7, 2023 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1999,7 +1999,20 @@ sudo ls /root echo $HOME $USER sudo bash -c 'echo $HOME $USER' sudo -H bash -c 'echo $HOME $USER' ---------------------------------------------------------------------------------------------------- cmd: sudo sh -c "go build ." problem: bash: line 1: go: command not found fix: # indicates that the go command is not in the system's PATH when running the command with sudo. #This is because sudo does not preserve the user's environment variables, including the PATH variable. sudo env "PATH=$PATH" sh -c "go build ." ---------------------------------------------------------------------------------------------------- #-H flag makes sudo assume root's home directory as HOME instead of the current user's home directory sudo -H #sudo user -
githubfoam revised this gist
Apr 7, 2023 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3425,6 +3425,25 @@ ls -ldi /. /.. ls -ldi /home/vagrant/. /home/vagrant/.. 3145730 drwxr-xr-x 7 vagrant vagrant 4096 Feb 22 10:14 /home/vagrant/. 3145729 drwxr-xr-x 3 root root 4096 Aug 24 08:48 /home/vagrant/.. ------------------------------------------------------------------------------------------ #ChatGPT Both .bashrc and .profile files are used for setting environment variables and defining user-specific configurations on Linux, but they have some differences in their purpose and usage. Here are some of the differences between .bashrc and .profile files: File Location: .bashrc is a Bash shell-specific initialization file that is located in the user's home directory. On the other hand, .profile is a generic shell initialization file that is also located in the user's home directory. Shell Usage: .bashrc is loaded for Bash shell instances only, while .profile is loaded for every shell instance (including Bash, Korn shell, Bourne shell, etc.) that is started. Invocation: .bashrc is invoked for non-login shells, while .profile is invoked for login shells. Content: .bashrc is typically used for setting Bash shell-specific configurations such as aliases, environment variables, and command prompt settings, while .profile is used for setting environment variables and other configurations that should be applied to all shells. Loading order: When a Bash shell instance is started, it first loads the /etc/profile file, which is a system-wide shell initialization file. After that, it loads the user's ~/.bash_profile or ~/.bash_login or ~/.profile file (in that order) if it exists. If none of these files exist, it loads the ~/.bashrc file. In summary, .bashrc is used for Bash shell-specific configurations, while .profile is used for general shell configurations that should apply to all shells. .bashrc is loaded for non-login shells, while .profile is loaded for login shells. ------------------------------------------------------------------------------------------ # The user file-creation mode mask (umask) /etc/profile -
githubfoam revised this gist
Dec 14, 2022 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2344,6 +2344,9 @@ dig +short localhost @8.8.8.8 journalctl -o json -n 10 --no-pager #change the format to format like JSON journalctl -o json-pretty -n 10 --no-pager cp /etc/systemd/journald.conf{,.orig} cp a.txt{,.$(date +%Y%m%d-%H%M)} #clone with date info sudo mkdir -p /var/log/journal ls -l /var/log/journal/3a0d751560f045428773cbf4c1769a5c/ sudo cp /etc/systemd/journald.conf{,.orig} -
githubfoam revised this gist
Nov 23, 2022 . 1 changed file with 29 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -584,6 +584,35 @@ hwclock --utc --systohc # set the hardware clock to match system (software) cloc ---------------------------------------------------------------------------------------------------- logger shutting down to add network card #create a log file entry noting that you’re manually shutting down the system to add a new network card prior to using shutdown, The logger utility can be used to create a one-time log fle entry that you specify ---------------------------------------------------------------------------------------------------- rsyslogd -v #Check if rsyslog is installed rsyslogd -f /etc/rsyslog.conf -N1 #Check Rsyslog Configuration for Errors semanage port -l| grep syslog #view the current SELinux ports settings for rsyslog semanage port -a -t syslogd_port_t -p udp 541 #add a UDP port 541 to SELinux #Verifying the Configuration #On the client server logger "Test message from the system `hostname`" nc -u 192.168.59.12 514 #verify connectivity to remote rsyslog server TCP port 50514 telnet 192.168.59.12 50514 #verify connectivity to remote rsyslog server TCP port 50514 #On the Centralized rsyslog server tail /var/log/messages tail –f /var/log/messages netstat –pnltu # Confirm That the Syslog Server Is Listening on Port 514 ss -tunlp | grep 514 ss -4altunp | grep 514 ss -tulnp | grep "rsyslog" nc -ulp 514 #cannot telnet to UDP port 514, use netcat #add the necessary UDP and/or TCP firewall rules to allow incoming syslog traffic # systemctl restart rsyslog # firewall-cmd --add-port=514/udp --permanent # firewall-cmd --add-port=514/tcp --permanent # firewall-cmd --reload ---------------------------------------------------------------------------------------------------- username must contain fewer than 32 characters and start with a letter may consist of letters, numbers, and certain symbols ---------------------------------------------------------------------------------------------------- -
githubfoam revised this gist
Oct 19, 2022 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4945,4 +4945,13 @@ $ sudo shutdown --halt +5 “Attention. The system is going down in five minutes $ sudo shutdown -c #Cancel a timed shutdown $ sudo shutdown -r now #restarting the system $ sudo systemctl reboot #restarting the system ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ #how to delete file with inode find . -inum 1847 -ls find . -inum 1847 -exec rm {} \; find . -inum 782263 -exec rm -i {} \; #how to delete directory/folder with inode find . -inum 393232 -delete ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -
githubfoam revised this gist
Oct 7, 2022 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3605,6 +3605,17 @@ userdel member2 # deletes the account but leaves the user’s home directory int userdel -f member2 # the -f option forces account deletion and fle removal under some circumstances userdel -r member2 # delete user account member2, the -r option to userdel causes it to delete the user’s home directory and mail spoo #disable root user sudo passwd -l root #lock the password for the root user sudo usermod -L root #lock the password for the root user sudo passwd -d root # remove the password of the account,can not unlock a locked account if it doesn't have any password #Enable Root Login sudo passwd root #set a new password for the account sudo passwd -u root #unlock the root user,unlock the password su root usermod -L testuser # lock user account / disable user account cat /etc/shadow | grep testuser # verify locked user account, exclamation mark "!" sudo passwd -S testuser #verify locked user account -
githubfoam revised this gist
Aug 31, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2504,7 +2504,7 @@ signal format $ ps -sx controlling terminal $ ps --tty 1 -s #print a process tree ps -ejH ps axjf -
githubfoam revised this gist
Aug 29, 2022 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2504,6 +2504,9 @@ signal format $ ps -sx controlling terminal $ ps --tty 1 -s #a process tree ps -ejH ps axjf list of command line arguments pstree -a -
githubfoam revised this gist
Aug 26, 2022 . 1 changed file with 20 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2571,7 +2571,7 @@ ionice -p 3467 #examine the class and priority used by PID 3467 ionice -c 1 -n 3 -p 3467 #set the I/O scheduling class to Idle,takes longer,no longer performance degradation # for pid in $(pidof rsync); do ionice -c 3 -p $pid; done ----------------------------------------------------------------------------------------------------- renice -n -19 -p 3534 -> Change the Priority of a Running Process #adding more virtual runtime to the process #The OS thinks that the process has taken more virtual runtime time than other processes in the run queue. @@ -2585,12 +2585,28 @@ renice -10 PID $ pidof rsync $ renice +10 2395 2395 (process ID) old priority 0, new priority 10 ----------------------------------------------------------------------------------------------------- #Process affinity is the scheduler property that helps to bind or unbind the process so that the process will run only with the allotted CPU #Processor affinity, or CPU pinning or “cache affinity”, enables the binding and unbinding of a process or a thread to a central processing unit (CPU) or a range of CPUs #According to the taskset command man pages, value f means "any CPU." $ pidof rsync $ taskset -p 2395 #use the PID to get CPU affinity, returns the current CPU affinity in a hexadecimal bit mask format pid 2395's current affinity mask: f $ taskset -cp 2395 #get the CPU range of a process pid 2395's current affinity list: 0-3 $ taskset -c 0 vlc #start the VLC program on CPU core ID 0 taskset 0xa gedit #launch gedit with CPU affinity 0xa. #If the server gets a reboot or the process is restarted, the PID changes taskset -p 0x11 9030 #assign a process to cores 0 and 4 taskset -cp 0,4 9030 #assign a process to cores 0 and 4 taskset -cp 1 9030 # bound the process 9030 to run only on CPU 1, configuration is not permanent ----------------------------------------------------------------------------------------------------- gpg --verify gnupg-2.2.3.tar.bz2.sig gnupg-2.2.3.tar.bz2 -> check the signature of the file gnupg-2.2.3.tar.bz2 ----------------------------------------------------------------------------------------------------- systemd-analyze #the actual boot time of the machine systemd-analyze blame #see how long every program and service takes to start up systemd-analyze critical-chain # print out the results in a chain of events style -
githubfoam revised this gist
Aug 26, 2022 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2573,8 +2573,21 @@ ionice -c 1 -n 3 -p 3467 # for pid in $(pidof rsync); do ionice -c 3 -p $pid; done renice -n -19 -p 3534 -> Change the Priority of a Running Process #adding more virtual runtime to the process #The OS thinks that the process has taken more virtual runtime time than other processes in the run queue. #in the next cycle, the CPU gives less time to the process #The process finishes late as it’s getting less time “on CPU” renice +10 PID #The OS thinks that the process hasn’t got enough “on CPU” time than other processes in the run queue #in the next cycle, the CPU gives more “on CPU” time to that process as compared to other processes in the run queue. renice -10 PID /etc/security/limits.conf -> set the default nice value of a particular user or group $ pidof rsync $ renice +10 2395 2395 (process ID) old priority 0, new priority 10 #Process affinity is the scheduler property that helps to bind or unbind the process so that the process will run only with the allotted CPU taskset gpg --verify gnupg-2.2.3.tar.bz2.sig gnupg-2.2.3.tar.bz2 -> check the signature of the file gnupg-2.2.3.tar.bz2 -
githubfoam revised this gist
Aug 26, 2022 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4895,4 +4895,11 @@ vim +/<employee id to be searched> <filename> #search for a specific Employee ID cd $mydir && python3 -m http.server 8888 #Share a file quickly using a web server podman run --rm -v .:/usr/share/nginx/html:ro,Z -p 30080:80 -d nginx # Expose a web directory using containers ------------------------------------------------------------------------------------------ $ sudo shutdown --halt 22:00 #--halt option stops the operating system $ sudo shutdown --halt +5 # halt the system after a five-minute delay $ sudo shutdown --halt +5 “Attention. The system is going down in five minutes.” $ sudo shutdown -c #Cancel a timed shutdown $ sudo shutdown -r now #restarting the system $ sudo systemctl reboot #restarting the system ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NewerOlder