1. Are you ready for the Galaxy S20? Here is everything we know so far!

The "Linux questions (and other stuff)" thread

Discussion in 'Computers' started by MoodyBlues, Jan 17, 2013.

  1. MoodyBlues

    MoodyBlues Choose compassion over cruelty
    VIP Member Thread Starter

    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 (Text):
    1. #!/bin/bash
    3. ls > /tmp/current_files
    4. mv /tmp/current_files ./current_files
    5. cat current_files | tr ' ' '_' > current_files_new
    6. FileCount=$(wc -l current_files | awk '{print $1}')
    7. count=1
    8. while   [ "$count" -le "$FileCount" ]
    9. do     ReadAwk="FNR=="$count
    10.     OldName=$(awk $ReadAwk current_files)
    11.     NewName=$(awk $ReadAwk current_files_new)
    12.     mv "$OldName" "$NewName" > /dev/null 2>&1
    13.     count=$(($count+1))
    14. done
    15. rm current_files
    16. rm current_files_new
    17. 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.


    #1 MoodyBlues, Jan 17, 2013
    Last edited: Jan 13, 2019
  2. argedion

    argedion The TechnoFrog

    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.

    [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.

  3. MoodyBlues

    MoodyBlues Choose compassion over cruelty
    VIP Member Thread Starter

    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?
  4. argedion

    argedion The TechnoFrog

    as in the example just Fantasy_7.jpg
  5. nickdalzell

    nickdalzell Android Expert

    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?
  6. 9to5cynic

    9to5cynic Android Expert

    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 (Text):
    1. ls > /tmp/current_files
    2. mv /tmp/current_files ./current_files
    3. [B]#makes file consisting of this directories
    4. #contents (after moving it from /tmp)[/B]
    5. cat current_files | tr ' ' '_' > current_files_new
    6. [B]#actually does the 'replacing' and creates a
    7. # new file for the underscore'd version....[/B]
    8. FileCount=$(wc -l current_files | awk '{print $1}')
    9. [B]#number of lines in original file... not sure what
    10. #awk is doing... that's the first argument right ($1) ??[/B]
    11. count=1  
    12. [B]#looks like this whole part is just moving the original
    13. #file to the underscored file one at a time.... I like this part a lot :)[/B]
    14. while   [ "$count" -le "$FileCount" ]
    15. do  ReadAwk="FNR=="$count  
    16. [B]#??? No clue what's happening here Setting FNR
    17. #to the current count level, but I don't know what FNR is?[/B]
    18.     OldName=$(awk $ReadAwk current_files)
    19.     NewName=$(awk $ReadAwk current_files_new)
    20.     mv "$OldName" "$NewName" > /dev/null 2>&1
    21.     count=$(($count+1))
    22. done
    23. [B]# removes files created.[/B]
    24. rm current_files
    25. rm current_files_new
    26. exit 0[/
  7. saptech

    saptech Android Expert

    Hey Moody, this is a great idea to start a Linux only thread. And I'm no good with scripts either, so I will need some help. In fact, I need something to help me get going with doing a partition backup using fsarchiver.

  8. 9to5cynic

    9to5cynic Android Expert

    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:

    < 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 :(
  9. MoodyBlues

    MoodyBlues Choose compassion over cruelty
    VIP Member Thread Starter

    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 (Text):
    1. [www.somesite.com]fantasy (10).jpg
    2. [www.somesite.com]fantasy (11).jpg
    3. [www.somesite.com]fantasy (12).jpg
    4. [www.somesite.com]fantasy (1).jpg
    5. [www.somesite.com]fantasy (2).jpg
    6. [www.somesite.com]fantasy (3).jpg
    7. [www.somesite.com]fantasy (4).jpg
    8. [www.somesite.com]fantasy (5).jpg
    9. [www.somesite.com]fantasy (6).jpg
    10. [www.somesite.com]fantasy (7).jpg
    11. [www.somesite.com]fantasy (8).jpg
    12. [www.somesite.com]fantasy (9).jpg
    I ran this script:

    Code (Text):
    1. #!/bin/bash
    3. # create a list of files that are in current directory, writing only
    4. # their names, in /tmp/current_files
    5. ls > /tmp/current_files
    7. # move the list of file names to current directory
    8. mv /tmp/current_files ./current_files
    10. # run contents of list file through tr, changing spaces into;
    11. # underscores; write modified results to new file
    12. cat current_files | tr ' ' '_' > current_files_new
    14. FileCount=$(wc -l current_files | awk '{print $1}')
    15. count=1
    16. while     [ "$count" -le "$FileCount" ]
    17. # this will get fed to awk for processing
    18. do     ReadAwk="FNR=="$count
    19.     OldName=$(awk $ReadAwk current_files)
    20.     NewName=$(awk $ReadAwk current_files_new)
    21. # use quotes so files with spaces in their names are interpreted
    22. # correctly; suppress any output
    23.     mv "$OldName" "$NewName" > /dev/null 2>&1
    24.     count=$(($count+1))
    25. done
    27. # clean up when done
    28. rm current_files
    29. rm current_files_new
    31. exit 0
    Now my files' names looked like this:

    Code (Text):
    1. [www.somesite.com]fantasy_(10).jpg
    2. [www.somesite.com]fantasy_(11).jpg
    3. [www.somesite.com]fantasy_(12).jpg
    4. [www.somesite.com]fantasy_(1).jpg
    5. [www.somesite.com]fantasy_(2).jpg
    6. [www.somesite.com]fantasy_(3).jpg
    7. [www.somesite.com]fantasy_(4).jpg
    8. [www.somesite.com]fantasy_(5).jpg
    9. [www.somesite.com]fantasy_(6).jpg
    10. [www.somesite.com]fantasy_(7).jpg
    11. [www.somesite.com]fantasy_(8).jpg
    12. [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 (Text):
    1. for file in \[www.somesite.com\]fantasy*.jpg
    2. do mv $file ${file#\[www.somesite.com\]}
    3. done
    My files now looked like this:

    Code (Text):
    1. fantasy_(10).jpg
    2. fantasy_(11).jpg
    3. fantasy_(12).jpg
    4. fantasy_(1).jpg
    5. fantasy_(2).jpg
    6. fantasy_(3).jpg
    7. fantasy_(4).jpg
    8. fantasy_(5).jpg
    9. fantasy_(6).jpg
    10. fantasy_(7).jpg
    11. fantasy_(8).jpg
    12. fantasy_(9).jpg
    Next comes this, which strips the "(" from each file's name:

    Code (Text):
    1. for file in *\(*.jpg
    2. do mv ${file} ${file/\(/}
    3. done

    Code (Text):
    1. fantasy_10).jpg
    2. fantasy_11).jpg
    3. fantasy_12).jpg
    4. fantasy_1).jpg
    5. fantasy_2).jpg
    6. fantasy_3).jpg
    7. fantasy_4).jpg
    8. fantasy_5).jpg
    9. fantasy_6).jpg
    10. fantasy_7).jpg
    11. fantasy_8).jpg
    12. fantasy_9).jpg
    Then this, to strip the ")" from each file's name:

    Code (Text):
    1. for file in *\)*.jpg
    2. do mv ${file} ${file/\)/}
    3. done

    Code (Text):
    1. fantasy_10.jpg
    2. fantasy_11.jpg
    3. fantasy_12.jpg
    4. fantasy_1.jpg
    5. fantasy_2.jpg
    6. fantasy_3.jpg
    7. fantasy_4.jpg
    8. fantasy_5.jpg
    9. fantasy_6.jpg
    10. fantasy_7.jpg
    11. fantasy_8.jpg
    12. 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'
    #9 MoodyBlues, Jan 18, 2013
    Last edited: Sep 29, 2019
    argedion likes this.
  10. mikedt

    mikedt 你好

    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.
  11. saptech

    saptech Android Expert

    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.
    mikedt likes this.
  12. mikedt

    mikedt 你好

    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;
    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.
    saptech likes this.
  13. saptech

    saptech Android Expert

    I've used Lynx before as well. I guess you can say I'm always behind the latest, greatest hardware, so using lightweight apps help keep my speed up to par when I had really old hardware.

    That's one thing I really like about Linux, you can do just about everything from CLI if X ever crash and you can't get it going soon enough.
  14. argedion

    argedion The TechnoFrog

    I also use vlc
  15. Speed Daemon

    Speed Daemon Android Expert

    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!
  16. palmtree5

    palmtree5 Sunny Vacation Supporter!

    Is there a good reason to use antivirus software in Linux? If so, recommendations? Also, what's the best way to do a system image backup?
  17. nickdalzell

    nickdalzell Android Expert

    why would Linux need anti-virus software?
  18. MoodyBlues

    MoodyBlues Choose compassion over cruelty
    VIP Member Thread Starter

    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.
  19. palmtree5

    palmtree5 Sunny Vacation Supporter!

    That's what I figured but I thought I would ask
  20. MoodyBlues

    MoodyBlues Choose compassion over cruelty
    VIP Member Thread Starter

    Glad you like it! :)

    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:

    I've never used fsarchiver, in fact I can't even recall hearing of it before. Regardless, what is it you want to do?
  21. Davdi

    Davdi Android Expert

    VLC for videos/movies Clementine for audio, Audacity for audio editing & manipulation.
  22. palmtree5

    palmtree5 Sunny Vacation Supporter!

  23. Bob Maxey

    Bob Maxey Android Expert

    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
  24. nickdalzell

    nickdalzell Android Expert

    while Linux CAN get viruses, the chances of it happening are like 1,000,000 to 1
  25. MoodyBlues

    MoodyBlues Choose compassion over cruelty
    VIP Member Thread Starter

    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
Similar Threads - Linux questions stuff
  1. Android News
  2. svim
  3. MoodyBlues
  4. semental
  5. Randymanme
  6. azalea4va
  7. en8vee
  8. GameTheory
  9. scporse
  10. deepakdeshp

Share This Page