Skip to main content

Posts

Showing posts with the label Copy selected files in Linux

Check Chrony logs on.Linux

Chrony service maintains synchronizing with external time sources like NTP servers. In Redhat, Rocky or Alma Linux, Chrony logs can be checked using journalctl. Example: sudo journalctl -u chronyd -xe The output will be limited only to the.log or entries of Chronyd service. To check status of Chronyd, use systemctl status chronyd To further check any log entries pertaining to chronyd, browse to /var/log cd /var/log And type: egrep "*chrony*" . This will check all log entries that has the string chrony, include the dot at the end to check all files on the current path. You can examine those files.if need to troubleshoot further, or just view the configuration of Chrony for any misconfiguration such as typo error, or unsupported Chrony settings. To view the chrony configuration,.type: grep ^[^#] /etc/chrony.conf This will view only the configuration that are currently enabled or uncommented lines, and also remove any blank lines. chronyc sources -v  The above command will show ...

Linux / WSL vi do save as or create password encryption

Vi / Vim is a powerful tool and for Linux enthusiast, this is a must tool to learn. Text file or basic editing in command line is quite important, to take notes, create a script, store text data or just anything that needs editing or creating via command line or terminal. How to create a text file in command line and put a password or encrypt the file? Text file is readable via lot of tools, cat, less, more, grep or any text editing files. One way to protect the file or its content is to encrypt the file. Screenshot below shows, how to create the file and encrypt it. Example: vi -x TestPasswordEncrypt.txt After entering the command, it will ask for an encryption key twice. And after entering the password, it will open the vi text editor, pressing "i" or the "insert" key then user can start entering text or typing on the vi window. After typing anything, press "esc" key and press :w (colon and w)  to save the file. If user need to save the file with a new f...

How to use Rsync to copy file one after another at a limited bandwidth

Copying files at the same time will ultimately consume all the bandwidth. So, to avoid such issue it would be good to tell Rsync to copy only once the other previous Rsync has finished copying. Copying or transferring files from one system to another location without impacting the bandwith or consuming all available bandwidth, when using Rsync. Using Rsync in Linux to copy files and folders is a common task for Sys Admin. When using Rsync and limiting the upper bandwith or telling Rsync the maximum bandwidth to use can be achieved using the "--limit" option. --limit is in KBps (Kilo Bytes per second and not Kilo bits) --partial is another good option if there is frequent disconnection this will tell Rsync to pick-up or include the files that has been transferred or copied Here's the command on how to use Rsync in Linux to limit the bandwidth when copying: rsync -Pz --limit=30000 <source> <destination> -P = will show the progress -z = tells Rsync to compress fi...

Nano editor shortcut keys

Nano editor in Linux is quite handy when working with text files in terminal window. Here's some keystroke that is quite useful when using Nano or editing text file with Nano. Ctrl + i  is like pressing the "Tab" key Ctrl + y will   go to top of the current displayed window or the top of the current nano screen Ctrl + v will go to the end of the current displayed window or the end of the current nano screen Ctrl + m  will move current line below the current cursor position Ctrl  + d will delete empty line                or will delete tab spaces                or will delete a single character if the line has text on it Ctrl + k   will cut the current line or current line will be cut and copied to clipboard (like Ctrl + x in word document if the text is highlighted) Ctrl + u   will paste the line that was cut or whatever is on the clipboard (like Ctrl /+ v in word doc...

Bash slice string in Linux Shell

Strings are quite basic in any scripting or programming languages. If a journey to a thousand miles starts with a single step, in the programming world the journey starts with a string called “Hello World” and beyond “Hello World” pseudocode and algorithm will keep the journey going.   Strings in scripting or programming are just group of characters. So, if string is a group of characters then it can be slice by character or a sub-string can be taken from the string. To slice a string in Bash, a syntax which is part of the Bash library can be used. Syntax is: ${string_to_be_sliced:slice_start_position:slice_end_position} Example string: slicethestring=“Hello Algorithm World” The string is stored in a variable: slicethestring To get the sub-string “Algorithm World”. Code will be:   echo ${slicethestring:6:23} #start the slice at position 6 till position 23 Another way to slice the string from a specified start position till the end; is to tell Bash the star...

Linux sed remove duplicates and get unique values

Removing duplicates and getting unique values is quite easy provided that the input data follows a specific format, for example the string or raw data has spaces in between. But a dilemma can occur if the data has no spaces in between the characters of the string, instead of spaces it is separated by dashes. So, how to remove duplicates, get the unique values and still retain the format of the raw data? Like this raw data: (just a sample string) the-quick-brown-fox-jumps-over-the-lazy-dog-jumps-over-the-lazy-cat-jumps-over-the-rabbit When removing duplicates and getting unique values via this command: sort duplicates.txt | uniq (this will work if the data is separated by spaces) duplicates.txt assumes that it has the string as illustrated above. Sample output: The output will be the exactly be the same with the input. Why? It is because the whole string is treated as literal one string, because the dashes connect between the character eliminat...

Create a new text file with content in Linux

Touch command in Linux will create an empty file in Linux command line. If no other parameters is specified whether a line will be inserted to the newly created file. Cat command is for reading files via command line but it can also be used to create a file in Linux terminal window command line. Cat command below will create a file called “test_comment.txt” and with the content or the line of “Hello World of Touch and Create File” on the file created. Here’s the shell command: cat  <( echo “Hello World of Touch and Create File”)  >  test_comment.txt Note that there is no space between “<(“, if there is a space then the command will not work as expected. Touch command to create a new file and also insert a new line or insert a string on the newly created file. Here’s the shell command: touch touch_file_comment.txt; echo “Hello World of Touch, insert this line.” >  touch_file_comment.txt Basically, the command exec...

How to copy a line using Nano editor?

Copying in Nano needs a few keys to copy and paste.  Copy and paste goes hand in hand, there’s no point to copy if you cannot paste. So, how to copy using Nano editor in Linux? To copy in Nano editor , a few key strokes are needed. On the beginning of the line that will be copied press: ctrl + 6 (to set a mark) Press “end” key or use right arrow to go to the end of the line. If multiple lines are to be copied used down arrow to select the lines. After selecting the line or lines to be copied, press: alt + 6 (to set unmark and all line/s selected is copied to the clipboard already. To copy the line or lines, position the cursor where the line/s will be copied and press: ctrl + u (this will paste the line/s or whatever is on the clipboard) That’s it, quite a few key strokes to remember but if you’re in a command line or in Putty; then these key combination to copy and paste in Nano is really a life saver. Cheers..till next ...

Check permission of the current directory in Linux

Checking permission of a current directory in Linux is quite simple and basic. The "ls" command will do the job. ls does not require sudo membership to use the command. Even if a directory has no files on it, just type: ls -lad This will show the permissions on the current directory where the command is typed. Even if the directory has no files or it is empty it will show the folder permissions. Consult "man ls" why ls -lad works to check permissions on empty folders. Typing, ls -ltr won't show anything if the folder is empty. Typing, ls -lad will show the permission whether the folder is empty. The ls command will display "." the current folder and ". .", basically this will show the hidden files and it's current permission settings. But by typing ls only or ls -ltr it won't show any permissions if the folder is empty since there are no files to display and thus no information is displayed. Cheers. Till next time....

Add a remote folder in Linux

Adding a remote folder in Linux or basically mounting a folder in Linux system is quite easy. Like in copying and moving files or folder, it requires a source and a destination. A simple copy command in Linux is:   cp --source or any file to be copied--  --destination or where to copy the file-- In mounting a folder, using mount command does require also a source and a destination. man mount will display the available options for this command. Since source and destination is a pre-requisite in cp, mv or   mount command. In mounting a remote folder, the destination folder must be ready or created first before typing the mount command. Linux has default destination for mounting folder which is /mnt folder. Mounting a remote folder can be also done on other location such /home /usr or other preferred locations. To mount a folder in /mnt directory, a sub folder must be created first. To create a folder, type: mkdir /mnt/rem...

Linux folder with special characters

Operating system or even applications programs does restrict some characters since it's either used by the system or it is not permitted for some other reasons. In Linux special characters like ampersand, dashes and other special characters should not be used as folder names or even file names. But some users or even IT folks violate this rule without knowing the consequences it holds. Of course, whatever characters available on the keyboard should be used or else what's the point of having them on the keyboard. :) But there are consequences in using those mentioned characters. In Linux terminal, if the folder name has an ampersand on its folder name like the image below it cannot be copied easily. For example navigating in Linux through the terminal using "cd" should be smooth but sometimes simple things can be tough if you don't know how to get around with it. Navigating folders with special characters using "cd " command is quite sim...