Skip to main content

Posts

Showing posts with the label Linux for noob

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 eliminating the space delimiter.
Example, if the requiremen…

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 executes two commands separated by “;” semi-colon. The first part is to cr…

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 time. :)


================================ Free Android Apps:
Click  link…

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.

==================…

How to use or configure rclone?

A quick tutorial on how to use Rclone.
Rclone is a good tool that is cross platform can be used on Windows or Linux.
Rclone can be used to sync and copy to AWS, Google drive and other cloud services.
To start using rclone it must be configured.
Typing: rclone config
Rclone config command will bring out the menu to config rclone. (see image below)


For example, if you need to configure rclone to connect to AWS S3.
Select “n” which means new remote.
Then type the name of the remote connection, which later can be used when syncing or copying files.  See image example below:



There will be some few questions after typing the name, just follow the on-screen questions and configured it for S3 settings.
Once the settings have been placed, rclone is now ready to sync or copy.
Rclone sync as stated on the manual, that the source and destination will be the same even if it means deleting files on the destination. Basically, the destination will be mirrored to the source, whatever is not on the …