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:
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.
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.
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?
Quote:
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.
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.
Device(s): HTC EVO 4g(Retired), HTC EVO LTE(Retired), LG Lucid(Returned), Motorola Droid Razr M, Nexus 7
Carrier: GOD
Thanks: 3,795
Thanked 4,026 Times in 1,994 Posts
Quote:
Originally Posted by MoodyBlues
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?
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?
__________________
Quote:
FATAL system error #nnnn
CAUSE: We should never get here!
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
#makes file consisting of this directories
#contents (after moving it from /tmp)
cat current_files | tr ' ' '_' > current_files_new
#actually does the 'replacing' and creates a
# new file for the underscore'd version....
FileCount=$(wc -l current_files | awk '{print $1}')
#number of lines in original file... not sure what
#awk is doing... that's the first argument right ($1) ??
count=1
#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 :)
while [ "$count" -le "$FileCount" ]
do ReadAwk="FNR=="$count
#??? No clue what's happening here Setting FNR
#to the current count level, but I don't know what FNR is?
OldName=$(awk $ReadAwk current_files)
NewName=$(awk $ReadAwk current_files_new)
mv "$OldName" "$NewName" > /dev/null 2>&1
count=$(($count+1))
done
# removes files created.
rm current_files
rm current_files_new
exit 0[/
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.
Device(s): Galaxy S3 (Verizon)
Evo 4G - retired/rooted
Carrier: Verizon
Thanks: 3,024
Thanked 1,721 Times in 1,162 Posts
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:
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.
Quote:
Originally Posted by MoodyBlues
What would you want the files to be renamed to?
Quote:
Originally Posted by argedion
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:
#!/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
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.
Device(s): Three Chinese Androids: Kliton I806LS, Lenovo P700i, Ampe A76
Carrier: O2, China Mobile(roaming)
Thanks: 1,376
Thanked 1,203 Times in 833 Posts
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.
__________________
The People's Guide to Android in the People's Republic.
Honorary Grand Poobah Shenzhen University English Corner. http://welcometomychina.tumblr.com/ There are nine million bicycles in Beijing.
There are nine million Androids in Shenzhen.
Last edited by mikedt; January 18th, 2013 at 03:35 AM.
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.
Device(s): Three Chinese Androids: Kliton I806LS, Lenovo P700i, Ampe A76
Carrier: O2, China Mobile(roaming)
Thanks: 1,376
Thanked 1,203 Times in 833 Posts
Quote:
Originally Posted by saptech
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.
┌┤...ker/Beethovens Symphonies Karajan├┐┌──────────────┤Playlist├──────────────┐
│22 Berliner Philharmoniker [ |MP3]││ │
│23 Berliner Philharmoniker [ |MP3]││ │
│24 Berliner Philharmoniker [ |MP3]││ │
│25 Berliner Philharmoniker [ |MP3]││ │
│26 Berliner Philharmoniker [ |MP3]││ │
│27 Berliner Philharmoniker [ |MP3]││ │
│28 Berliner Philharmoniker [ |MP3]││ │
│29 Berliner Philharmoniker [ |MP3]││ │
│30 Berliner Philharmoniker [ |MP3]││ │
│31 Berliner Philharmoniker [ |MP3]││ │
│32 Berliner Philharmoniker [ |MP3]││ │
│33 Berliner Philharmoniker [ |MP3]││ │
│34 Berliner Philharmoniker [15:31|MP3]││ │
│35 Berliner Philharmoniker [ |MP3]││ │
│36 Berliner Philharmoniker [ |MP3]││ │
│37 Berliner Philharmoniker [06:22|MP3]││ │
│38 Berliner Philharmoniker [ |MP3]││ │
├────┤Playing... ├──────────┤ Master 27% ├───┤>000:31:26├┤
│ > 37 Berliner Philharmoniker - Beethoven 09x04 (Beethovens Symphonies Karajan│
│00:46 05:36 [06:22] 44kHz 256kbps [STEREO] [NET] [SHUFFLE] [REPEAT] [NEXT] │
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.
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.
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!
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.
Hey Moody, this is a great idea to start a Linux only thread.
Glad you like it!
Quote:
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!
Quote:
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?
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.
One good reason is because not everyone uses Linux, so being able to scrub out malware in a relatively secure environment is a good practice. Linux powers many file and web servers that Windows and Macintosh computers connect to. I know that I wouldn't want to find out from an irate client that I gave them some malware!
While Linux itself is relatively secure (if you patch it religiously and practice good basic security protocols), there have been some Linux exploits. (The word "virus" is hopelessly out of date.) I'd rather have ClamAV scan my Linux machines' filesystems from time to time just in case.
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.
By practicing the same basic security protocols on my Windows NT machines, I've never had any of those infected with any malware either. A little common sense can do a lot of good.
Also if you're using linux desktop and connecting or trading files with Windows machine, it wouldn't hurt to have an antivirus program installed.
I've never had a virus on my linux machines since the mid 1990s, but I've never had one on my Windows machines either. Well once, my teenage son did get one visiting porn sites. I've never ran a virus scanner on linux but did try ClamAV just to see how it ran.
Most those seem to be experimental or proof of concepts from the late 90s. Or they involve the users doing something, like opening a malicious document, code injection. Hopefully no Linux users are running something like OpenOffice, or internet browser, or IM, or e-mail client with root privileges, e.g. "$ sudo openoffice" Which is something Windows does by default. all software runs with admin/root privileges. Although MS have tried to stop that.
As a teacher in China, I'm always opening potentially malicious and dangerous documents. I'm using Linux, but if LibreOffice or MS Office on Wine, suddenly asked for my root password, because of some document trying to do something to the system. I'd immediately know, something is wrong here.
This why logging in as root is always a bad idea. I've never had to do that. Login as root is sometimes hidden in certain distros, to protect novice users from themselves, and you don't need it anyway.
Last edited by mikedt; January 18th, 2013 at 08:37 PM.
By practicing the same basic security protocols on my Windows NT machines, I've never had any of those infected with any malware either. A little common sense can do a lot of good.
How does NT compare to *nix in terms of its inherent security, vis-à-vis its file system, permissions, user privileges, etc.?
Device(s): Three Chinese Androids: Kliton I806LS, Lenovo P700i, Ampe A76
Carrier: O2, China Mobile(roaming)
Thanks: 1,376
Thanked 1,203 Times in 833 Posts
Quote:
Originally Posted by MoodyBlues
How does NT compare to *nix in terms of its inherent security, vis-à-vis its file system, permissions, user privileges, etc.?
I'm not the expert. But I'm sure it's mostly file-system permissions and user privileges. In *NIX OSs the system wont try to run something if it isn't marked as "executable". You would never mark a JPG as "executable", so the system wouldn't try to run it. So even if there was malicious code inside a JPG, it wouldn't run.
Windows on the other hand, everything is executable, EXE, BMP, GIF, JPG, MP3, WAV, DOC, PPT, etc. This is why you get malicious BMPs, GIFs, MP3s, DOCs, that have code inside them, which can be executed by say a buffer-overflow vulnerability(code injection). And if the system is running as admin or root, as Windows does by default, it's pwned, as they say.
if i double click on a JPG in Ubuntu, it opens up whatever picture viewer is default, just like windows. i don't believe executable exists in Linux--everything is a file!
Now our college used and we were required to have our own version (trial) of WinNT 4 and Win2K and i do know the Guest account cannot even set the system time! much less change sensitive info. a 'user' in Linux (i do not recall there being sub-groups in *nix such as guest, power user, and so on just user and root) has more power. a 'user' can use his own user password (Ubuntu does not set a separate root password in its installer ) to sudo anything. there is no security when a person can simply use a generic user password to gain even temporary root priviledge, which can be dangerous in itself. but i don't see too many Linux users complaining about problems the way Windows does.
Last edited by nickdalzell; January 18th, 2013 at 09:14 PM.
Device(s): Three Chinese Androids: Kliton I806LS, Lenovo P700i, Ampe A76
Carrier: O2, China Mobile(roaming)
Thanks: 1,376
Thanked 1,203 Times in 833 Posts
Quote:
Originally Posted by nickdalzell
if i double click on a JPG in Ubuntu, it opens up whatever picture viewer is default, just like windows. i don't believe executable exists in Linux--everything is a file!
Oh it definitely does. Appications are certainly executable on Linux, e.g. Chrome. Just that they don't usually have any file suffix. .bin might be used sometimes, to indicate a binary/executable file.
Here's the file permissions for a JPG, it's actually my AF avatar. This is on Mint, which is Ubuntu based.
Everyone can open it and look at it, but they can't change or modify it, or change the file permissions. The only users who can do that are "michael" (me) and root. Note that "make the file executable" is unchecked. The OS would never try to run it, even if there was code hidden inside.
Quote:
Originally Posted by nickdalzell
Now our college used and we were required to have our own version (trial) of WinNT 4 and Win2K and i do know the Guest account cannot even set the system time! much less change sensitive info. a 'user' in Linux (i do not recall there being sub-groups in *nix such as guest, power user, and so on just user and root) has more power. a 'user' can use his own user password (Ubuntu does not set a separate root password in its installer ) to sudo anything. there is no security when a person can simply use a generic user password to gain even temporary root priviledge, which can be dangerous in itself. but i don't see too many Linux users complaining about problems the way Windows does.
You are the "administrator" for your own system, in the absence of a corporate sysadmin. And so the user password is the sudo and root password for your own system. You can set a seperate, password and admin/root account if you want for Ubuntu. There's nothing stopping you from doing that. Which is what enterprise users would do.
Last edited by mikedt; January 18th, 2013 at 09:56 PM.
if i double click on a JPG in Ubuntu, it opens up whatever picture viewer is default, just like windows.
That's not what mikedt is referring to. Automatically opening a JPEG in the default image viewer is not the same thing as executing a JPEG. It's the image viewer that's being executed in this scenario, not the image FILE.
Quote:
i don't believe executable exists in Linux--everything is a file!
Nope! Want a quick, very brief, and not all-inclusive lesson on Linux file attributes?
Every file--and this includes directories, because they're files, too--can have three types of permissions, for three sets of users: read/write/execute for user/group/others. So let's say you have a bash script saved as a file named do_this in your home directory, and its permissions look like this:
Code:
-rwxr-xr-x 1 nick users 248600 2013-01-17 22:45 do_this
See the rwx? Those are the permissions for you (user), and they signify read, write, and execute. Then see the two r-xs? Those are for group and others, and they signify read and execute permission only. You can do anything you want to this file, including editing it or deleting it, while everyone else can look at its contents and can execute it, but they can't modify or delete it.
Quote:
Now our college used and we were required to have our own version (trial) of WinNT 4 and Win2K and i do know the Guest account cannot even set the system time! much less change sensitive info.
Just keep in mind that [just about] anything micro$oft has is [probably] a rip-off, and [usually] a very POOR implementation, of something that originated in *nix.
Quote:
a 'user' in Linux (i do not recall there being sub-groups in *nix such as guest, power user, and so on just user and root)
*nix has always...always provided for different levels of authority, everything from who could write to tape drives to who could log in only on a terminal and not the server. Again, anything m$ has likely originated in UNIX.
Quote:
has more power. a 'user' can use his own user password (Ubuntu does not set a separate root password in its installer ) to sudo anything. there is no security when a person can simply use a generic user password to gain even temporary root priviledge, which can be dangerous in itself. but i don't see too many Linux users complaining about problems the way Windows does.
No, that's not how it works. Only a user who has been granted the right to use sudo can use it. Typically, that person would be the one in charge of administering the system.
Ubuntu and its offspring decided that making it harder to enable a true root login would lead to less catastrophe from windows converts. While I certainly see their point, I still think it's a stupid, unnecessary step. As I've said elsewhere, as soon as I install any *buntu or derivative on a new computer, I give root a password AND I enable root logins. I'm a big girl. I don't need hand holding at this point!
and what if that user tried to use the sudo command and entered his/her own password? same problem
No, that's not how it works. As I said, a user has to be granted the right to use sudo in order to use it. If they're not in the sudoers file, they can't use the command.
BTW Moody how is this thread going to work when it has like three different subjects going at once? how do you sort it in one thread?
Good question! Unfortunately, I don't have a good answer. In fact, I don't have ANY answer. I guess people who either have a question about, or think they can answer questions about, Linux will pop in here and see what's up.
BTW Moody how is this thread going to work when it has like three different subjects going at once? how do you sort it in one thread?
Can it be a subfolder under the Lounge folder like the others there? Then when someone have a certain question, they can create a new Thread. Similar to how the Politics, Computer & IT, and the others are designed.
I do have a question though. This is more generic than having to do with bash and whatnot. Well sort of. Anyway!
Source based distros (Gentoo, Sourcery, etc.) Do you think that they are better than distros such as Ubuntu? I understand that Gentoo and the like are not for your average/novice Linux user. I tried Gentoo, and I for the life of me could not get it to work.
Regardless. Which do you think is better for the most part? Or is it one of those "case to case" things?
Device(s): Three Chinese Androids: Kliton I806LS, Lenovo P700i, Ampe A76
Carrier: O2, China Mobile(roaming)
Thanks: 1,376
Thanked 1,203 Times in 833 Posts
Quote:
Originally Posted by nickdalzell
BTW Moody how is this thread going to work when it has like three different subjects going at once? how do you sort it in one thread?
This why we "quote" whom we're responding to. So everyone can follow a particular subject or conversation. If not, I'd just assume it's a response to the OP, or the post above, or it's just a general comment for the thread. It's something we've always done for usenet and mailing lists, and forums are not really any different.
Your post mentioned Moody, but I felt it needed an answer that I could give.
I do have a question though. This is more generic than having to do with bash and whatnot. Well sort of. Anyway!
Source based distros (Gentoo, Sourcery, etc.) Do you think that they are better than distros such as Ubuntu? I understand that Gentoo and the like are not for your average/novice Linux user. I tried Gentoo, and I for the life of me could not get it to work.
Regardless. Which do you think is better for the most part? Or is it one of those "case to case" things?
I think Source based distros are relevant to those that only want to install what they need. In a server operation this could work out for the benefit if you need specific compilation on the hardware you're using.
The average users really don't need it, plus with newer hardware may not be worth it.
Sourcemage is my favorite SBD, but I haven't messed with it a couple of years.
You're a female and know a great deal about Linux??? Wow, I'm in luv!
Yep, last time I looked, I was female! And I've been a *nix-ster since 1985. I actually switched career paths because of UNIX. Long story, but I needed a break before starting medical school, one thing led to another, and I ended up in a created-just-for-me position at the furniture store chain where I worked [doing data entry] while in college. I transitioned them off their IBM System/3s, creating a multi-location and, of course, multi-user UNIX system. I did everything--installing hardware, administering the system, programming, all of it. That was my favorite job ever.
I occasionally ruminate over the fact that I always intended to be a physician, and I essentially blew 5 years of hard work [A student, with honors] in pre-med, but for the most part I'm fine with it. When something comes up, like the brain tumor I had, I do find myself wishing I had gone on with med school so I could be more involved in my care, but those thoughts are few and far between.
i started when i was in college, heard about this 'Free' OS for awhile and found linux.org (site seems to have changed owners and looks completely different now) and downloaded Basiclinux, my first distro--had to compile everything. X windows actually booting up without a WM or DE was at the time something to be proud of at least for me, and using the links browser in frame buffer graphics mode was a feat in engineering in BL. but unfortunately it was not ready to replace Windows. that did not end up happening 100% until a few days ago. but i did distro hop in and out of Windows space a bit, i bought the complete Red Hat 7 set, six discs with a couple for source code, every app that was available in the repos at time of release. wow. but eventually Netscape couldn't keep up so back to Windows i went. also, RH 7 wouldn't run Bearshare--it would load the app but it would not connect. and that was a heavy used app at the time. also, my CD Burner refused to play nice with the old software it had. suddenly having every app released at the time of the disc set was not as impressive as it was when i bought it. i later burned the first Ubuntu, of course being stupid, as a deer lover myself i liked the name Feisty Fawn. but it really had zero support for a very used Compaq 1200 series. no support for PCMCIA, USB wifi, or anything i used. but it did have sound and the video going. but without internet was essentially useless. back to Windows. then came Mandriva. hard disc decided to go into an infinite activity loop and the distro refused to boot, couldn't fsck either as it woule auto reboot when entering root password. back to Windows. well you can see what ended up happening by my past threads here.
Device(s): HTC EVO 4g(Retired), HTC EVO LTE(Retired), LG Lucid(Returned), Motorola Droid Razr M, Nexus 7
Carrier: GOD
Thanks: 3,795
Thanked 4,026 Times in 1,994 Posts
recently working on a project that called to find out if a file existed or not I had no idea of how to do this in Linux. Not being always the sharpest tool in the shed I tried several ways and failed miserably. I searched a little but since I suck at searching (never know really what to ask) somehow though i seemed to have found my way and its really simple.
here is a test condition to find if a file exist or not using bash
if [[ -e "filename" ]] ; then
true
else
false
fi
just thought I would share for those who didn't know
recently working on a project that called to find out if a file existed or not I had no idea of how to do this in Linux. Not being always the sharpest tool in the shed I tried several ways and failed miserably. I searched a little but since I suck at searching (never know really what to ask) somehow though i seemed to have found my way and its really simple.
here is a test condition to find if a file exist or not using bash
if [[ -e "filename" ]] ; then
true
else
false
fi
just thought I would share for those who didn't know
Is it okay if I post the contents of your PM here? Do you even still need help with it? Putting it here will benefit others, too, plus someone besides me can chime in!