• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

The "Linux questions (and other stuff)" thread

With all the splintered discussions about Linux around here, I thought perhaps we could have a thread dedicated to all things Linux. Whether you're a new Linux user, or someone considering installing Linux, or have specific questions or solutions about a Linux feature or program, how about posting here? I'll start by pasting in some code I posted in a totally non-computer related thread!

The following bash code will replace spaces in file names with underscores:

Code:
#!/bin/bash

ls > /tmp/current_files
mv /tmp/current_files ./current_files
cat current_files | tr ' ' '_' > current_files_new
FileCount=$(wc -l current_files | awk '{print $1}')
count=1
while   [ "$count" -le "$FileCount" ]
do     ReadAwk="FNR=="$count
    OldName=$(awk $ReadAwk current_files)
    NewName=$(awk $ReadAwk current_files_new)
    mv "$OldName" "$NewName" > /dev/null 2>&1
    count=$(($count+1))
done
rm current_files
rm current_files_new
exit 0

My advice is that you try it first in a temporary directory with copies of files, just to verify for yourself that it works as expected. Also, if you're unsure what any part of it does, feel free to ask.

Edited to change how new forum software displays code blocks.
 
Last edited:
Great Idea. hopefully this becomes one of my newest hangouts. I'm always looking to learn something new.

so let me ask the first question. I download a file (graphic) from a website that puts its name in brackets along with the name of the file.

example
[www.somesite.com]fantasy (7).jpg

what would be the best way to rename the file without having to do a full rename of each and every file? for the sake of this example lets say ten files.

thanks
 
Upvote 0
Great Idea. hopefully this becomes one of my newest hangouts. I'm always looking to learn something new.
Let's hope it takes off. When I realized that questions like the 'spaces in file names' one were popping up in threads that had NOTHING to do with computing, let alone Linux, it just seemed like having a central place would be so much more convenient. I mean who--after say a month or six--will REMEMBER that the question about removing spaces from file names was in a 'what's going on in your neck of the woods' thread? :thinking:

so let me ask the first question. I download a file (graphic) from a website that puts its name in brackets along with the name of the file.

example
[www.somesite.com]fantasy (7).jpg

what would be the best way to rename the file without having to do a full rename of each and every file? for the sake of this example lets say ten files.
What would you want the files to be renamed to?
 
  • Like
Reactions: MrJavi
Upvote 0
Let's hope it takes off. When I realized that questions like the 'spaces in file names' one were popping up in threads that had NOTHING to do with computing, let alone Linux, it just seemed like having a central place would be so much more convenient. I mean who--after say a month or six--will REMEMBER that the question about removing spaces from file names was in a 'what's going on in your neck of the woods' thread? :thinking:


What would you want the files to be renamed to?

as in the example just Fantasy_7.jpg
 
Upvote 0
speaking of filename problems is there some means to get around certain glitches in Wine on a 64-Bit system/OS because a lot of times i had to install the 32-bit OS version because Wine cannot ever find it's 'program files' directory and gives me the 'returned empty string' error and segfaults/crashes. this is because the folder is called 'Program Files (x86)' and for some reason the () symbols are not valid in the syntax of starting or using Wine programs....does renaming the folder properly cause issues or is there another way?
 
Upvote 0
[high]#!/bin/bash

ls > /tmp/current_files
mv /tmp/current_files ./current_files
cat current_files | tr ' ' '_' > current_files_new
FileCount=$(wc -l current_files | awk '{print $1}')
count=1
while [ "$count" -le "$FileCount" ]
do ReadAwk="FNR=="$count
OldName=$(awk $ReadAwk current_files)
NewName=$(awk $ReadAwk current_files_new)
mv "$OldName" "$NewName" > /dev/null 2>&1
count=$(($count+1))
done
rm current_files
rm current_files_new
exit 0[/high]
I'm a bit of a scripting newb, but can I try to decipher this and see if I'm right?
I'll do comments below for visibility... :)

Code:
ls > /tmp/current_files
mv /tmp/current_files ./current_files 
[B]#makes file consisting of this directories 
#contents (after moving it from /tmp)[/B]
cat current_files | tr ' ' '_' > current_files_new 
[B]#actually does the 'replacing' and creates a
# new file for the underscore'd version....[/B]
FileCount=$(wc -l current_files | awk '{print $1}') 
[B]#number of lines in original file... not sure what 
#awk is doing... that's the first argument right ($1) ??[/B]
count=1  
[B]#looks like this whole part is just moving the original 
#file to the underscored file one at a time.... I like this part a lot :)[/B]
while   [ "$count" -le "$FileCount" ]
do 	ReadAwk="FNR=="$count  
[B]#??? No clue what's happening here Setting FNR 
#to the current count level, but I don't know what FNR is?[/B]
	OldName=$(awk $ReadAwk current_files)
	NewName=$(awk $ReadAwk current_files_new)
	mv "$OldName" "$NewName" > /dev/null 2>&1
	count=$(($count+1))
done
[B]# removes files created.[/B]
rm current_files
rm current_files_new
exit 0[/
 
Upvote 0
Okay, I've got a question about bluetooth...

I'm in BT5r3, trying to add a keyboard via command line. With the GUI, I am almost able to get it to sync every time (I have to search, then setup using the 'proceed without pairing' option). Sometimes it just doesn't work, not sure why?

Well, I can't find anything command line that works. For some reason there are no bluez-* utilities (even though I installed everything from the repos related to bluez* last night).

using hcitool scan finds my device.
I just set it up with the gui, and using hcitool con reveals this:

Connections:
< ACL BT_ADDRESS handel 11 state 1 lm MASTER AUTH ENCRYPT

any ideas?

EDIT: In my LM live usb, I can set it up with a couple of commands by using bluez-*, but as that's not in BT, it won't work for this :(
 
Upvote 0
so let me ask the first question. I download a file (graphic) from a website that puts its name in brackets along with the name of the file.

example
[www.somesite.com]fantasy (7).jpg

what would be the best way to rename the file without having to do a full rename of each and every file? for the sake of this example lets say ten files.

What would you want the files to be renamed to?

as in the example just Fantasy_7.jpg

As with all things Linux/UNIX, there are many ways to do what you're after. Ask 1,000 different people and you'll probably get 2,000 different answers! :) With that in mind, here's what I came up with; I'm showing it step by step for clarity, rather than just throwing it all into one script.

First, I ran the script posted earlier to replace spaces with underscores (this time I've added a little documentation! :)). So I started out with 12 files named:

Code:
[www.somesite.com]fantasy (10).jpg
[www.somesite.com]fantasy (11).jpg
[www.somesite.com]fantasy (12).jpg
[www.somesite.com]fantasy (1).jpg
[www.somesite.com]fantasy (2).jpg
[www.somesite.com]fantasy (3).jpg
[www.somesite.com]fantasy (4).jpg
[www.somesite.com]fantasy (5).jpg
[www.somesite.com]fantasy (6).jpg
[www.somesite.com]fantasy (7).jpg
[www.somesite.com]fantasy (8).jpg
[www.somesite.com]fantasy (9).jpg

I ran this script:

Code:
#!/bin/bash

# create a list of files that are in current directory, writing only
# their names, in /tmp/current_files
ls > /tmp/current_files

# move the list of file names to current directory
mv /tmp/current_files ./current_files

# run contents of list file through tr, changing spaces into;
# underscores; write modified results to new file
cat current_files | tr ' ' '_' > current_files_new

FileCount=$(wc -l current_files | awk '{print $1}')
count=1
while     [ "$count" -le "$FileCount" ]
# this will get fed to awk for processing
do     ReadAwk="FNR=="$count
    OldName=$(awk $ReadAwk current_files)
    NewName=$(awk $ReadAwk current_files_new)
# use quotes so files with spaces in their names are interpreted
# correctly; suppress any output
    mv "$OldName" "$NewName" > /dev/null 2>&1
    count=$(($count+1))
done

# clean up when done
rm current_files
rm current_files_new

exit 0

Now my files' names looked like this:

Code:
[www.somesite.com]fantasy_(10).jpg
[www.somesite.com]fantasy_(11).jpg
[www.somesite.com]fantasy_(12).jpg
[www.somesite.com]fantasy_(1).jpg
[www.somesite.com]fantasy_(2).jpg
[www.somesite.com]fantasy_(3).jpg
[www.somesite.com]fantasy_(4).jpg
[www.somesite.com]fantasy_(5).jpg
[www.somesite.com]fantasy_(6).jpg
[www.somesite.com]fantasy_(7).jpg
[www.somesite.com]fantasy_(8).jpg
[www.somesite.com]fantasy_(9).jpg

Next I typed this at a prompt to remove the [www.somesite.com] from each file's name:

Code:
for file in \[www.somesite.com\]fantasy*.jpg
do mv $file ${file#\[www.somesite.com\]}
done

My files now looked like this:

Code:
fantasy_(10).jpg
fantasy_(11).jpg
fantasy_(12).jpg
fantasy_(1).jpg
fantasy_(2).jpg
fantasy_(3).jpg
fantasy_(4).jpg
fantasy_(5).jpg
fantasy_(6).jpg
fantasy_(7).jpg
fantasy_(8).jpg
fantasy_(9).jpg

Next comes this, which strips the "(" from each file's name:

Code:
for file in *\(*.jpg
do mv ${file} ${file/\(/}
done

Yielding:

Code:
fantasy_10).jpg
fantasy_11).jpg
fantasy_12).jpg
fantasy_1).jpg
fantasy_2).jpg
fantasy_3).jpg
fantasy_4).jpg
fantasy_5).jpg
fantasy_6).jpg
fantasy_7).jpg
fantasy_8).jpg
fantasy_9).jpg

Then this, to strip the ")" from each file's name:

Code:
for file in *\)*.jpg
do mv ${file} ${file/\)/}
done

Yielding:

Code:
fantasy_10.jpg
fantasy_11.jpg
fantasy_12.jpg
fantasy_1.jpg
fantasy_2.jpg
fantasy_3.jpg
fantasy_4.jpg
fantasy_5.jpg
fantasy_6.jpg
fantasy_7.jpg
fantasy_8.jpg
fantasy_9.jpg

Done! :D

Please ask questions if you're not sure what/how/why something is being done in any of the above.

My caveat, as before, is to first try this in a dummy directory that contains *COPIES* of your files. That way, if something doesn't work right, or you make a typo, or whatever, you don't risk losing anything important. Once you're satisfied that it works as expected it, do it for real.

09/29/19 - changed old forum's 'high' tag to 'code'
 
Last edited:
Upvote 0
Here's a question. What is everyone's favourite music player/management application? Myself, I like Rhythmbox. It seems to be reliable and does everything I need, it even syncs my 80GB Apple iPod Video. :) There's quite a few to choose from. I did try Banshee for a while, but did find a problem with it, which I've already discussed somewhere on the forums recently. For podcasts I use GPodder, although I've not tried any other podcast aggregators.
 
  • Like
Reactions: MrJavi
Upvote 0
I use VLC the most for music & videos, but I do use others. My other lightweight favorites are MOC (Music On Console) & Audacious. I've been using these for years.

I just tried that one, it works OK...it never occured to me to use the CLI for playing my music library. LOL. VLC is my default video player, and has been so for a long time.


[HIGH]&#9484;&#9508;...ker/Beethovens Symphonies Karajan&#9500;&#9488;&#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9508;Playlist&#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
&#9474;22 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;23 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;24 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;25 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;26 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;27 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;28 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;29 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;30 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;31 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;32 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;33 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;34 Berliner Philharmoniker [15:31|MP3]&#9474;&#9474; &#9474;
&#9474;35 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;36 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9474;37 Berliner Philharmoniker [06:22|MP3]&#9474;&#9474; &#9474;
&#9474;38 Berliner Philharmoniker [ |MP3]&#9474;&#9474; &#9474;
&#9500;&#9472;&#9472;&#9472;&#9472;&#9508;Playing... &#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9508; Master 27% &#9500;&#9472;&#9472;&#9472;&#9508;>000:31:26&#9500;&#9508;
&#9474; > 37 Berliner Philharmoniker - Beethoven 09x04 (Beethovens Symphonies Karajan&#9474;
&#9474;00:46 05:36 [06:22] 44kHz 256kbps [STEREO] [NET] [SHUFFLE] [REPEAT] [NEXT] &#9474;
[/HIGH]
I've done browsing many times using the CLI, with Lynx. Sites usually load very quickly as well, which can be useful sometimes in bandwidth challanged China.
 
Upvote 0
VLC is a perennial favorite for me too.

I really like the layout and features in Amarok, and used it for a long time. But because I hand-edit the file metadata when I rip a CD using abcde, I don't care for apps that mess with the metadata. I don't want to have to be constantly fixing my music files to remove poor spelling and ID3 tags that contain some stranger's editorials!
 
  • Like
Reactions: MrJavi
Upvote 0
speaking of filename problems is there some means to get around certain glitches in Wine on a 64-Bit system/OS because a lot of times i had to install the 32-bit OS version because Wine cannot ever find its 'program files' directory and gives me the 'returned empty string' error and segfaults/crashes. this is because the folder is called 'Program Files (x86)' and for some reason the () symbols are not valid in the syntax of starting or using Wine programs....does renaming the folder properly cause issues or is there another way?
I've never seen any of what you're describing, including the '(x86)' in the directory name, but I'd start by renaming 'Program Files (x86)' simply 'Program Files' and see if that does it.
 
  • Like
Reactions: MrJavi
Upvote 0
Hey Moody, this is a great idea to start a Linux only thread.
Glad you like it! :)

And I'm no good with scripts either, so I will need some help.
Believe it or not, I'm *SO* rusty on all aspects of programming, including bash scripting, so it's kind of fun trying to force my brain back into that mode. Hopefully, *I* won't be the only one contributing on script questions! :eek:

In fact, I need something to help me get going with doing a partition backup using fsarchiver.
I've never used fsarchiver, in fact I can't even recall hearing of it before. Regardless, what is it you want to do?
 
  • Like
Reactions: MrJavi
Upvote 0
Clarify . . . are you saying that if I run Linux, there is absolutely no possible way I will suffer a virus?

I took a look and remember, I am not an expert.

Meet Linux Viruses | Unixmen
Let me put it this way--and please keep in mind that I've used *nix since 1985, okay? In *MY* experience, a properly configured, administered, and maintained *nix system will not have any type of security issue, including viruses. For the record, in 28 years, NONE of my UNIX/Linux computers and/or networks has ever been compromised. :D
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones